- Home /
Rigidbody velocity has got different direction than VelocityChange force vector
I want my GameObject to move to direction +y direction with a constant speed.
I chose to apply VelocityChange type fordce to a rigidbody. The force applied: (0,10,0) The Rigidbody properties: mass of 1, Use Gravity: false, Is Kinematic: false.
public class moveForward : MonoBehaviour
{
public Vector3 force;
void Start ()
{
print("v0: " + GetComponent<Rigidbody>().velocity);
GetComponent<Rigidbody>().AddForce(force,ForceMode.VelocityChange);
print("f: " + force);
}
int fuCounter = 0
void FixedUpdate()
{
if(0==(fuCounter%50))
{
print("v: " + GetComponent<Rigidbody>().velocity);
}
++fuCounter;
}
}
My expectation was that I measure a velocity which equals the velocity vector I added, namely (0,10,0). Instead I got (0.0, 9.0, -1.1).
v0: (0.0, 0.0, 0.0)
f: (0.0, 10.0, 0.0)
v: (0.0, 0.0, 0.0)
v: (0.0, 9.0, -1.1)
v: (0.0, 9.0, -1.1)
...
The force and velocity vector do not point into the same direction:
What is the reason of this difference?
something else is going on. I just tested your code in an otherwise empty scene and it worked fine. v: 0,10,0
@42p Have you checked you did not change the center of mass of the object? As far as I remember it should be (0,0,0) as it is a relative coordinate to the transform position
Changing the center of mass doesn't change anything in this case. AddForce always applies the force at the center of mass. AddForce itself does never change the angularVelocity, only AddForceAtPosition would cause this.
If the velocity doesn't match the given force direction there must be another force applied. $$anonymous$$ost likely a collision with another object. $$anonymous$$aybe the object is spawned / positioned so it overlaps another collider.
You are right, I have done a mistake. I never realized that AddForce never change the angularVelocity. Very interesting anyway.
Thank you for your help. It turns out I had the collider of the plane on the picture enabled. The cylinder and the plane collided on a small area.
Answer by 42p · Dec 05, 2016 at 07:33 AM
I managed to get rid of the problem. I disabled the collider of the plane, which I forgot to do before. Now it works fine.