- Home /
The question is answered, right answer was accepted
rigidbody.velocity.x also affecting z-axis?
Hi! I'm currently working on a 3D Platformer and trying out some stuff, making very great progress so far. But there's one problem I have:
I have 2 Box Colliders, one on the Player (just for testing) and one on a block. When I now change the velocity of the player on the x-axis while he's standing on a block, he's also moving slightly on the z-axis (this also affects the enemies with box colliders). I already tried it with the player being in the air, and there it's working properly, so I assume the issue must be the 2 box colliders. Of course there aren't any rotations and the gravity is set to default (only y-axis).
Sorry for this noob question, but it really bothers me.
Is the player collider overlapping the Box's collider? If so the Penalty Force from the corner of the Box is pushing your Rigidbody in the direction the corner is facing.
I have a couple of questions relating to this in my list. Take a look; they were hacked, not solved. It all came down to Skin Widths and Penalty Force.
(I'm calling it Penalty Force - I remember reading this term was applied to the Force applied to separate colliders within each other. I could be wrong; someone please correct me if I am).
I tried a lot of stuff, like rotating the block 180° around Y, with the same direction the player is drifting off. For now I ended up with setting velocity.z to 0 during movement - not the most elegant version and will probably give me conflicts soon.
Applying a character controller to my player just mixed everything up - I actually avoided that until now, since I didn't really seem to need it. Is it a "must-have", since you mentioned Skin Widths?
Answer by meat5000 · Jun 19, 2014 at 06:40 PM
Character controller not essential :)
Try moving the block left then right just a little bit to see if penalty force is kicking in the the edges and corners. Make the box collider much bigger than the player to see if it's still happening.
I was kinda generalising with Skin width. As well as the CC there's also the Penalty Force setting in Physics manager.
Using Rigidbodies and physics will always introduce some kind of error.
If you want it to stick to an axis, try adding a small relative force, proportional to the distance away from target to gently push the Rigidbody back on track.
Yep, the relative force is working perfectly. Thank you very much! :)