Page 1 sur 1

[Résolu] Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 8:21
par falsam
Bonjour. J'ai un souci avec la physic. Sinbad refuse de chuter :wink:

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
    
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
  
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
  
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Add3DArchive(#PB_Compiler_Home +"Examples/3D/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
    
  KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
  
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)

  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
  
  ; Physics
  EnableWorldPhysics(#True)
  WorldGravity(-20)

  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 0)
  
  Mesh      = LoadMesh(#PB_Any, "sinbad.mesh")
  Player    = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 10, 600, -40)
  ScaleEntity(Player, 25, 25, 25)
  CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 20)
  EntityAngularFactor(Player, 0, 1, 0)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
  
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard() 
    
    ExamineKeyboard()
    
    ;-Evenement clavier : Déplacement
    If KeyboardPushed (#PB_Key_Up)
      PlayerSpeed = 300
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Down)
      PlayerSpeed = -300
      CurrentAnimation = "RunBase"
    Else
      CurrentAnimation = "IdleTop"
      PlayerSpeed = 0
    EndIf
    
    ;-Evenement clavier : Rotation
    If KeyboardPushed (#PB_Key_Left)
      RotateEntity(Player, 0, 3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Right)
      RotateEntity(Player, 0, -3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    EndIf   
    
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf 
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)

    ;Play animation
    If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
      StartEntityAnimation(Player, CurrentAnimation)
    EndIf
        
    RenderWorld()
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End  
EndProcedure

d'avance merci pour votre aide.

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 8:29
par SPH
Il y a un probleme avec ton ombre. Elle ne te suis pas.

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 8:32
par falsam
SPH a écrit :Il y a un probleme avec ton ombre. Elle ne te suis pas.
C'est normal car Sinbad ne touche pas le sol.

Bien sur je pourrais le poser au sol. Mais je veux que Sinbad se positionne avec la physic.

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 8:39
par SPH
Haaa, fallait le savoir. Je pensais que tu voulais qu'il tombe en quittant le sol (ca n'empeche que j'ai repondu de travers plus haut)

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 9:12
par falsam
Nouveau code. J'ai supprimé ce qui ne sert à rien.

Il y a un sol et deux cubes. Un seul cube chute. Je ne comprend pas !

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
    
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
  
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
  
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
      
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
  
  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 0)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)  
  Player    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 10, 600, -40)
  CreateEntityBody(Player, #PB_Entity_BoxBody, 1, 1, 1)
  
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
  
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard() 
    
    ExamineKeyboard()
        
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf 
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)
        
    RenderWorld()
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End  
EndProcedure

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 9:34
par falsam
je suis une quiche !!!! MoveEntity() maintient Sinbad en l'air :|

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 11:10
par falsam
Je pense que mon souci est résolu. Voici le nouveau code. Si quelqu'un a mieux je suis preneur.

Utiliser les touches du clavier pour vous déplacer et shooter dans la caisse ;)

Code : Tout sélectionner

EnableExplicit

Global camera

; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
  Exit()
CompilerEndIf

Start()

Procedure Start()
  Protected Window, ww, wh, Event
  Protected Texture, Material, Mesh
  Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
  
  ; Initialisation de l'environnemet 3D
  If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
    MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
    Exit()
  EndIf
   
  ; Window & Screen 3D
  Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
  ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
  wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
  SetWindowColor(Window, 0)
 
  OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
 
  ; Localisation des elements 3D
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Add3DArchive(#PB_Compiler_Home +"Examples/3D/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
   
  KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
 
  ; Camera
  camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
  MoveCamera(camera, 0, 10, 40)

  ; Environnement
  SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)

  CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
  WorldShadows(#PB_Shadow_Additive)
 
  ; Physics
  EnableWorldPhysics(#True)
  WorldGravity(-20)

  ;- Entités
  Texture   = LoadTexture(-1, "Dirt.jpg")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
  Ground    = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
  CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 100)
 
  Mesh      = LoadMesh(#PB_Any, "sinbad.mesh")
  Player    = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 10, 600, -40)
  ScaleEntity(Player, 25, 25, 25)
  CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 200, 1, 100)
  EntityAngularFactor(Player, 0, 1, 0)
 
  Texture   = LoadTexture(-1, "Caisse.png")
  Material  = CreateMaterial(-1, TextureID(Texture))
  Mesh      = CreateCube(-1, 100)
  Box       = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
  CreateEntityBody(Box, #PB_Entity_BoxBody, 100, 1, 100)
 
  ; Render
  While #True
    event = WindowEvent()
    ExamineKeyboard()
      
    ;-Evenement clavier : Déplacement
    If KeyboardPushed (#PB_Key_Up)
      PlayerSpeed = 200
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Down)
      PlayerSpeed = -200
      CurrentAnimation = "RunBase"
    Else
      CurrentAnimation = "IdleTop"
      PlayerSpeed = 0
    EndIf
   
    ;-Evenement clavier : Rotation
    If KeyboardPushed (#PB_Key_Left)
      RotateEntity(Player, 0, 3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    ElseIf KeyboardPushed (#PB_Key_Right)
      RotateEntity(Player, 0, -3, 0, #PB_Relative)
      CurrentAnimation = "RunBase"
    EndIf   
   
    If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
      Exit()
    EndIf

    If PlayerSpeed
      DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
      MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
    EndIf
    
    CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)

    ;Play animation
    If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
      StartEntityAnimation(Player, CurrentAnimation)
    EndIf
       
    RenderWorld(100)
    FlipBuffers()
  Wend
EndProcedure

Procedure Exit()
  End 
EndProcedure

Re: Souci avec la Physic : CreateEntityBody()

Publié : mar. 14/juil./2020 11:30
par venom
Pas mieux a te proposé car je suis une quiche ne 3D.
Mais ça a le mérite de fonctionner maintenant 8)






@++