- Home /
Movement based on collision on a custom mesh
I'm working on a 3D racing game, with a custom mesh (a semi-cylindrical downward spiral) as the track and a sphere as the player.
I've attached the mesh collider component to the track and a rigid body component with a spherical collider to the sphere (with gravity and kinematic off). When I place the sphere at the beginning of the track, it happily rolls down the track till the end. Great!
Now, I want the player to be able to move this sphere left and right (to escape obstacles). To accomplish this, I'd need to be able to define fixed local axes for the sphere (so Z represents forward, and X represents right). Now, the physics based rolling of the sphere rotates all the axes, so I can't use transform.forward and transform.right (since they're always changing).
How can I go about accomplishing this? I was thinking of may be using the collision normal (of the contact point of the sphere with the mesh), but I'd like to know if I'm missing something.
Thanks.
Edit: I've tried onCollisionStay and using the collision normal to help me define the local axes, but the sphere jumps out of the track (and falls off..). I want the sphere to move left and right based on the user input and bank the track but not fall off. Is character controller something I should look into for this?
Your answer
Follow this Question
Related Questions
Player getting stuck in ground (3D) player has Rigidbody, and Box Collider, world is Mesh Colliders 0 Answers
Moving a 3D player without player controller 1 Answer
How can the player position updates randomly when the player isn't movingl? 0 Answers
How to add platform motion to player controller without parenting? - Mostly working code 1 Answer
Mouse drag through Maze without relying on collision 1 Answer