- Home /
Freezing rotation breaks friction for BoxColliders
I have a pretty simple 3d scene with a box collider representing the player on top of a large, flat, and planar box collider. When I apply force on the player's rigidbody purely on the positive x-axis, I also get positive motion on the z-axis. When I apply force purely on the positive z-axis, I also get motion on the positive x-axis. Finally, when I apply force purely on the negative z-axis, I also get motion on the negative x-axis.
I'm a beginner to unity, so it's possible I'm overlooking something stupid. I would expect that when I apply force on one axis, I wouldn't see motion on another. This effect is absent without gravity, so I guess it's due to friction. Is this an unavoidable side effect of the physics engine?
I'm applying the force simply as follows:
void FixedUpdate() {
myRigidBody.AddForce(Vector3.right * Input.GetAxis("Horizontal") * WALK_FORCE);
myRigidBody.AddForce(Vector3.forward * Input.GetAxis("Vertical") * WALK_FORCE);
}
Update: Disabling useConeFriction on the player's rigidbody as well as increasing the physics iteration count in the project settings greatly reduces this effect, although it's still present
Update 2: I believe this is a bug with the way rotation is frozen in the physics engine. I have uploaded a demonstration of this issue here. Use WASD to move the two objects in the scene. If you watch the box object in the Scene Hierarchy, you will see that as you move it back and forth along one axis, it will also move on the other. If you watch the sphere object, you will see it does not have this effect.
This appears to be due to the fact I've frozen my Rigidbody's axes of rotation. Is it not possible to have a nonrotating BoxCollider move properly over a planar collider?
if you want to have the character in physics yes it is
but you can make your character ignore all physics
and rigidbody set to ignore gravity forgot some more things but this is basic principle
try
float X = Input.Getaxis("Horizontal")
float y = 0;
float z = 0;
transform.Translate (X,Y,Z);
in addition you can try 2 very good $$anonymous$$chers:
most recommended: https://www.youtube.com/watch?v=zraYNRX54A4 don't worry he $$anonymous$$ches all stuff from beginning
https://www.youtube.com/watch?v=0Tl1Cc0IRnI&list=UUPXOQq7PWh5OdCwEO60Y8jQ∈dex=34
Answer by iwaldrop · Jan 19, 2013 at 12:57 AM
You can do what you're talking about, but you aren't going to want to apply a force. You're going to want to directly translate the transform -- aka controlling your rigidbody via kinematics. Check the box marked 'is kinematic' on your rigidbody and try the following.
transform.position = transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * WALK_FORCE);
And go ahead and give it a shot without that box checked. I forget if the box will still want to be fricative or not, but if it doesn't then at least you can still bump it around using physics.
Also, you might experiment with changing Vector3.right/forward to transform.right/forward. They mean totally different things and will produce very different results depending on the orientation of your rigidbody. I hope that helps you. Enjoy!
Thanks for your response. In my project, no objects can rotate. The player may have to push boxes around a room, for example. Even if I control the player as a kinematic rigidbody, when he interacts with these boxes I will again see the same effect.
To me, this sounds like a bug in the way rotation is frozen. It seems like the cube is actually rotating a bit, incurring forces due to that rotation, and then it's rotation is reset at the end of the physics frame. For example, with a sphere I do not observe this effect...
Your answer
Follow this Question
Related Questions
How to make moving objects stack, without sliding over each other? 0 Answers
Calculating required force for pushing a body to a desired position at once 0 Answers
What is the appropriate value of Friction Direction 2? 1 Answer
How can I change friction of a Physic material in script? 1 Answer
Angular Friction 0 Answers