Collisions between static and kinematic bodies, integrating logic and physics in a game #71
-
I would like to understand why the collision between a mesh cube and the ground works only on position [0,0,0] of the ground ... Is this possible to make body visible on the view to see if i have to scale the shape ? Mesh are imported from blender and convert to jsx with gtlftojsx. Thank you a lot ! https://codesandbox.io/s/github/Franckapik/NandY/tree/master/views?file=/src/3d/Game.js https://github.com/Franckapik/NandY/blob/master/views/src/3d/Game.js |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hello @Franckapik ! J'ai simplifié votre exemple jusqu'à où je pense que nous pouvons voir le problème: You were setting the player's position via the API, preventing collisions. I know this is not the file you directly linked to, but in looking through your game it seems you were not using In useFrame(() => api.position.set(y, 0.1, x)); |
Beta Was this translation helpful? Give feedback.
-
Hello @stockhuman ! I'm sorry, i didn't realize that i updated my github so my codesandbox too. I was talking about Game.js file indeed where all meshes was imported from blender. Now, your simplified version (and thank you for this by the way !) is not using gltf... If i remove the line you said, the collision between "Joueur" and the ground works, but how to move the "Joueur" to play the game next ? Thank you very much for responding ! |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I'm going to point you to the FAQ:
Since your player, walls and floor are all Kinematic or static, you will not see collisions between them. Are you looking to perhaps Regarding glTF, I'm not sure that's related to your problem. If you'll provide another sandbox with your progress we can see what's up. |
Beta Was this translation helpful? Give feedback.
-
Thank you @stockhuman . I will write roughly on a sheet of paper your citation about collision and kinematic body. So now, it's true that i have to make a choice between physic-based movement and logic ones... I prefered experiment the physics-based movement and i tried to use applyLocalImpulse but without sucess... I confess that i am a little embarrassed with the docs concerning this function. I didn't found example using it, have you got one ? Thank you!! |
Beta Was this translation helpful? Give feedback.
-
Hello @Franckapik, pardon the late reply - I hope you managed to figure out what you want to go with for your game. Here's a very basic demo of |
Beta Was this translation helpful? Give feedback.
-
Thank you!! Now i see how to use ApplyImpulse. I have to decide if i prefer use Logic or Physic now to move my player ;) |
Beta Was this translation helpful? Give feedback.
Unfortunately, I'm going to point you to the FAQ:
Since your player, walls and floor are all Kinematic or static, you will not see collisions between them.
Are you looking to perhaps
applyLocalImpulse
or force with every player movement? The player box would not move as you've defined it to so far, however. Or to rephrase that, are you looking for physics-based movement of the p…