- Home /
Gravity only rigidbody
I want my player's vehicle to be affected by gravity, yet when it moves, I want it to be by a set speed, and I don't want it to be affected by other physics. Should I just use the rigidbody for y direction movement, and restrict everything else, spinning and moving through translating? Or should I manipulate the speed through relative velocity?
Answer by Owen-Reynolds · Feb 04, 2012 at 06:31 PM
This is exactly what a characterController is for. Assuming you can't use it because the collider is the wrong shape (a real capsule collider can be flipped forwards, like a submarine shape, but the charController one is locked into straight up.)
You can't usefully move an RB with Translate -- translate "goes around" physics, going through solid objects, such as tunneling through hills.
Locking the move dirs makes it so the good way to move an RB (setting velocity,) won't work. It can't tell between the velocity you set and what collisions give. Constraints just ignore all velocity, and you never move.
The simplest way for an RB to "ignore" being hit is to jack up the Mass. Another way is, suppose you always have your set speed in Vector3 myVel;
. Update tweaks that and sets rigidbody.velocity=myVel;
. So, any velocity you get from collisions is cancelled next Update.
I haven't tried this, but you could also add that to OnCollisionEnter. That might immdediately reset "pushed" velocity before it moves you for even that frame.
Right now, since I'm prototyping, a capsule collider would be fine, but I want to eventually have the player piloting a large mech, so I want to make sure that if someone fires between the arm and body, it doesn't count as a hit, so I can't use one large capsule in the end.
Could I possibly use characterController for multiple noncapsule colliders?
CharControllers only really move properly with that one y-axis capsule they give you. The compound collider trick, which works for rigidbodies great, doesn't work for them. You can add more colliders to them, which work fine for other things hitting them, but the built-in move doesn't see them -- they get pushed right through other colliders.
Your answer
Follow this Question
Related Questions
Physics gravity appears very weak 2 Answers
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
How can I match Unity's gravity implementation per object? 1 Answer
My objects keep falling through 1 Answer