Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm doing some experiments trying to figure out how physics works in Unity.

I created a cube mesh with a BoxCollider and a RigidBody. The cuve is laying on a mesh plane with a BoxCollider.

I'm trying to update the object position applying a force on its RigidBody. Inside script FixedUpdate function I'm doing the following:

public void FixedUpdate()
{
    if (leftButtonPressed())
        this.rigidbody.AddForce( this.transform.forward * this.forceStrength, ForceMode.Impulse);
} 

Despite the object is aligned with the world axis and the force is applied along Z axis, it performs a quite big rotation movement around its y axis. Since I didn't modify the center of mass and the BoxCollider position and dimension, all values should be fine.

Removing gravity and letting the object flying without touching the plane, the problem doesn't show. So I suppose it's related to the friction between objects, but I can't understand exactly which is the problem.

Why this? What's my mistake? How can I fix this, or what's the right way to do such a moving an object on a plane through a force impulse?

share|improve this question
1  
Have you tried to set the objects' materials? My answer isn't ok? –  fableal Oct 17 '12 at 14:59
add comment

1 Answer

I tried to replicate your example and you're right:

I had to set the plane's material to Ice to see the cube moving as it should. Without a material set to the plane, the cube won't "slide" forward (will do a simple somersault) for values like 25, and for bigger values (like 250) the cube's behaviour is really weird!!! (it moves forward, that moves backwards, then starts flying in the upper direction!!! Really funny; here is a link to a video).

To have access to the Ice material you have to import the Physic Materials package.

To set the plane's material you have to select the plane and go to Mesh Collider -> Material.

share|improve this answer
    
+1: yes, actually using ice (dynamic and static friction low, friction/bouncing combine minimum) reduce this problem. I still don't understand the reason. –  Heisenbug Oct 22 '12 at 12:55
    
Might be due to the physics engine (friction, ...), if you try lowering the cube's mass, you don't have to set materials at all. –  fableal Oct 22 '12 at 14:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.