1
\$\begingroup\$

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?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Have you tried to set the objects' materials? My answer isn't ok? \$\endgroup\$
    – fableal
    Commented Oct 17, 2012 at 14:59

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ +1: yes, actually using ice (dynamic and static friction low, friction/bouncing combine minimum) reduce this problem. I still don't understand the reason. \$\endgroup\$
    – Heisenbug
    Commented Oct 22, 2012 at 12:55
  • \$\begingroup\$ 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. \$\endgroup\$
    – fableal
    Commented Oct 22, 2012 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .