Je ne connais pas le but de ton code, mais j'ai réfléchi un peu sur le trajet de ton entité sur un plan incliné à 45 degrés. Tu devrais peut être utiliser l'objet
.
.
■ Avec le code ci-dessous, je te propose de faire circuler un cube sur un chemin qui emprunte une passerelle comportant deux plans inclinés à 45 degrés. Ce code n'est pas parfait mais montre les possibilité de l'objet spline. Les points de passage sont matérialisés par des sphères blanches que tu peux supprimer en commentant les lignes CreateMarker()
Code : Tout sélectionner
EnableExplicit
Enumeration
#Mainform
EndEnumeration
Define.l Event
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Global Camera, Texture.i, Material.i, Mesh.i, Entity.i, N.f, StepX.f
Global SPLine, Time.f, x.f, y.f, z.f, StepValue.f, TimeSinceLastFrame.f
Procedure CreateMarker (x.f, y.f, z.f)
CreateEntity(#PB_Any, MeshID(CreateSphere(#PB_Any, 0.1)), #PB_Material_None, x, y, z)
EndProcedure
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()
OpenWindow(#Mainform,0,0,1024,768, "Suivre un chemin", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Mainform),0,0,1024,768,0, 0, 0)
KeyboardMode(#PB_Keyboard_International)
;
;Lumiere et ombre
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Modulative, 0, RGB(175, 175, 175))
;
;Une camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(145, 182, 201))
MoveCamera(Camera, 0, 8 , 15, #PB_Absolute)
CameraLookAt(Camera, 0, 0, 0)
;
;Texture & Material
Texture = CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(Texture))
Box(0,0,256,256,RGB(0, 0, 0))
Box(1,1,252,252,RGB(255, 216, 0))
StopDrawing()
Material = CreateMaterial(#PB_Any, TextureID(Texture))
MaterialFilteringMode(Material, #PB_Material_Anisotropic, 6) ;Meilleurs rendu du materiel
;
;Creation du sol
Mesh = CreatePlane(#PB_Any, 50, 50, 1, 1, 6, 6)
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
EntityPhysicBody(Entity, #PB_Entity_StaticBody)
;
;Mise en place d'un obstacle à franchir ayant ce profil /¯¯\
;Premier profil /
Entity = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 3)), MaterialID(Material), -2.5,1,0)
ScaleEntity(Entity, 1, 0.05, 1, #PB_Absolute)
RotateEntity(Entity, 0, 0, 45)
;Deuxiéme profil ¯¯
Entity = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 3)), MaterialID(Material), 0,2,0)
ScaleEntity(Entity, 1, 0.05, 1, #PB_Absolute)
;Troisiéme profil \
Entity = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 3)), MaterialID(Material), 2.5,1,0)
ScaleEntity(Entity, 1, 0.05, 1, #PB_Absolute)
RotateEntity(Entity, 0, 0, -45)
;
;Création du cube qui va suivre un chemin passant par cet obstacle
Entity = CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 1)), MaterialID(Material))
;
;Création de l'objet chemin
spline = CreateSpline(#PB_Any)
; On indique des points de passages du chemin
; Les différentes coordonnées auraient pu être placées dans une liste ou un tableau
CreateMarker(-8, 0.6, -15) ;Balise coin haut gauche
AddSplinePoint(spline, -8, 0.6, -15)
CreateMarker(-8, 0.6, 0) ;Balise coin bas gauche
AddSplinePoint(spline, -8, 0.6, 0)
CreateMarker(-4, 0.7, 0) ;Balise entrée du premier plan à 45° ./
AddSplinePoint(spline, -4, 0.7, 0)
CreateMarker(-1.5, 2.7, 0) ;Balise bord gauche du plan horizontal °¯¯
AddSplinePoint(spline, -1.5, 2.7, 0)
CreateMarker(1.5, 2.7, 0) ;Balise bord droit du plan horizontal ¯¯°
AddSplinePoint(spline, 1.5, 2.7, 0)
CreateMarker(4, 0.7, 0) ;Balise sortie du deuxiéme plan à 45° \.
AddSplinePoint(spline,4, 0.7, 0)
CreateMarker(8, 0.7, 0) ;Balise coin bas droit
AddSplinePoint(spline, 8, 0.7, 0)
CreateMarker(8, 0.6, -15) ;Balise coin haut droit
AddSplinePoint(spline, 8, 0.6, -15)
;L'entité passera par ces points et reviendra au premier point
AddSplinePoint(spline, -8, 0.6, -15) ;Premier point
;Sa vitesse est déterminée par la valeur du pas (Valeur décimale)
StepValue = 3.00
;Nous voila dans la boucle evenementielle
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
ExamineKeyboard()
If KeyboardPushed (#PB_Key_Escape)
Break
EndIf
;Calcule la position du point de déplacement (offset) spécifié.
ComputeSpline(spline, time)
;Une fois que le point a été calculé, sa position est disponible
x = SplineX(spline)
y = SplineY(spline)
z = SplineZ(spline)
;L'entité regarde en direction de ces trois points
EntityLookAt(Entity, x, y, z)
;Et on le positionne sur ces coordonnées
MoveEntity(Entity, x, y, z, #PB_Absolute)
;Ou en est ton dans notre déplacement ?
time + StepValue * TimeSinceLastFrame / 35
;La valeur de décalage varie de 0.0 à 1.0
If time > 1 ;fin de la spline
Time = 0 ;début de la spline
EndIf
;Quel est le temps écoulé depuis la dernière image en millisecondes.
TimeSinceLastFrame = RenderWorld() / 1000
; Affiche le rendu de la scène
ClearScreen(RGB(0, 0, 0))
RenderWorld(80)
FlipBuffers()
ForEver