- Home /
How do I make a rigidbody bounce off a mesh collider?
Notice: All of the code I provide will be in C#. I'd prefer answers in C#, but Javascript should be fine as I'll probably be able to translate the given code into C#.
So here's what I've got right now:
The player's ship (which has a box collider attached). It is a non-kinematic rigidbody since it is controlled by the physics engine. So when the player presses the move forwards key:
rigidbody.AddRelativeForce(-moveSpeed,0,0);
I also have an environment which has a mesh collider attached. What I want to do is make the player's ship bounce off the environment, but I'm not sure how to do this. I tried messing with a physics material a little bit, but couldn't figure anything out from just messing around with it, as my ship flew through my environment mesh regardless of what settings I had.
Also, when the ship collides, there are some other things I'd like to have happen (such as the ship taking damage and whatnot). Is there a function that I can use to do this? My efforts with OnCollisionEnter have been unsuccessful in the sense that I can't get the function to call, though I have gotten onTriggerEnter to call successfully.
Thanks in advance for the assistance!
Your answer
Follow this Question
Related Questions
Adding another rigid body causes object to fall? 0 Answers
Stop Objects from stacking on top of each other? 1 Answer
Is there a way to automatically make physics collider frictionless on sides but not on top? 2 Answers
Too sensitive GameObjects 1 Answer
Not all sides of a cube collide properly( with pic) 2 Answers