C'est curieux, je n'ai jamais vu "import Blender". Bon, j'ai pas fait beaucoup de script sur Blender aussi... De quels tutos tu parles ?
Néanmoins, si tu ouvres un template dans Blender ou que tu fouilles dans tes addons installés, tu verras plutôt "import bpy" :
Nhésite pas également à te référer à la doc de l'API Blender. A noter que l'API est en train de changer pour la version 2.80 qui devrait sortir fin octobre.
En fait je cherche a pouvoir dans un premier temps déplacer un cube dans un labyrinthe. Ce labyrinthe est contenu dans la matrice : les "1" sont des murs.
Voici mon premier programme :
from random import randrange
from time import*
import bge
import blender
cont = bge.logic.getCurrentController()
own = cont.owner
Manette=bge.logic.joysticks[0]
objet=Blender.Object.Get('personne_1') #objet à déplacer
def spawn():
global matrice,orientation,localisation
alea=randrange(0,2)
if alea==0:
objet.setLocation([0,0,0])#à remplir : il y a deux points possibles de départ (deux coins)
localisation=[1,1]
orientation=2 #bas
else:
objet.setLocation([0,0,0]) #à remplir
localisation=[15,1]
orientation=0 #haut
print('spawn')
def verif_devant():
global matrice,orientation,localisation,ok
if orientation==0:
if matrice[localisation[0]-1][localisation[1]]!=1:
ok=True
localisation[0]-=1
else:
ok=False
elif orientation==1:
if matrice[localisation[0]][localisation[1]+1]!=1:
ok=True
localisation[1]+=1
else:
ok=False
elif orientation==2:
if matrice[localisation[0]+1][localisation[1]]!=1:
ok=True
localisation[0]+=1
else:
ok=False
else:
if matrice[localisation[0]][localisation[1]-1]!=1:
ok=True
localisation[1]-=1
else:
ok=False
def verif_derriere():
global matrice,orientation,localisation,ok
if orientation==0:
if matrice[localisation[0]+1][localisation[1]]!=1:
ok=True
localisation[0]+=1
else:
ok=False
elif orientation==1:
if matrice[localisation[0]][localisation[1]-1]!=1:
ok=True
localisation[1]-=1
else:
ok=False
elif orientation==2:
if matrice[localisation[0]-1][localisation[1]]!=1:
ok=True
localisation[0]-=1
else:
ok=False
else:
if matrice[localisation[0]][localisation[1]+1]!=1:
ok=True
localisation[1]+=1
else:
ok=False
def main():
global jeu,orientation,ok
while jeu==True:
if Manette.axisValues[1]==1:
for i in range(30):
objet.setEuler([0,0,3])
sleep(0.03) #-> tourne a peu près en une seconde
orientation=(orientation+1)%4
elif Manette.axisValues[1]==-1:
for i in range(30):
objet.setEuler([0,0,-3])
sleep(0.03) #-> tourne a peu près en une seconde
orientation=(orientation+1)%4
elif Manette.axisValues[0]==1:
verif_devant()
if ok==True:
for i in range(10):
objet.setLocation([0.1,0,0])
sleep(0.1)
elif Manette.axisValues[0]==-1:
verif_derriere()
if ok==True:
for i in range(10):
objet.setLocation([-0.1,0,0])
sleep(0.5)
#variables
jeu=True
matrice=[
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1],
[1,0,1,1,1,0,1,0,0,0,1,0,1,1,1,0,1],
[1,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,1],
[1,0,1,0,1,1,0,1,0,0,0,1,1,0,1,1,1],
[1,0,0,0,0,0,0,1,0,1,0,0,1,0,0,0,1],
[1,1,1,1,1,0,1,1,0,1,1,0,1,0,1,0,1],
[1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1],
[1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1],
[1,0,0,1,0,0,1,0,0,0,1,1,0,1,1,1,1],
[1,1,0,1,0,0,1,1,0,1,1,1,0,0,0,0,1],
[1,1,0,1,1,0,0,1,0,0,0,0,1,1,0,0,1],
[1,1,0,0,0,1,0,1,0,1,1,0,0,0,0,1,1],
[1,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,1],
[1,0,1,1,0,1,0,1,1,1,0,0,0,1,1,0,1],
[1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
orientation=0 #0 haut,1 droite,2 bas,3 gauche
ok=True
#fonctions
print('debut')
spawn()
main()
Les déplacements sont choisis graçe à un joystick usb.
Je pense qu'il y a plusieurs problèmes dans ce profgramme ...
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Moderateur forum || FAQ 3D || discord 3D francophone || OC Tweak script
Moderateur forum || FAQ 3D || discord 3D francophone || OC Tweak script