- Home /
Rigid body add force, slow reactions.
I've got a rigid body that is pulled towards my mouse position however if I move the mouse to the other side of the screen, the time it takes the object to slow down and change position to head in the other direction is too slow and carries on moving in the wrong direction for too long before switching to the new direction.
public float pullForce = 1;
public Transform player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// calculate direction from target to me
Vector3 forceDirection = transform.position - player.transform.position;
// apply force on target towards me
player.rigidbody.AddForce(forceDirection.normalized * pullForce * Time.fixedDeltaTime * 10);
}
This is attached to my mouse position game object. Any ideas of how to add in a "dampener" that I can use to control the speed at which the player object reacts to a change in force?
You could try setting the rigidbody velocity to it's transform.position when the direction changes, and then apply the new force towards the new direction. Alternatively, you can also just use
this.transform.Translate((moveVector.normalized * speed) * Time.deltaTime, Space.World);
where moveVector is the the target position. I like this particular way of moving rigidbodies because they don't have the annoying, if somewhat realistic, slowing down issues when changing direction or stopping.
Answer by Lasse-Loepfe · Sep 16, 2014 at 11:19 PM
The delay is caused by the inertia, the resistance of any physical object to any change in its state of motion, including changes to its speed and direction.
If you want to wrok with rigidbodies, you could directly adress velocity, using a lerp to avoid aprupt changes.
Vector3 desiredDirection = transform.position - player.transform.position;
rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, desiredDirection , changeRate * Time.deltaTime);
This is exactly what I was trying to achieve, thanks!
Your answer
Follow this Question
Related Questions
Applying a force to multiple objects at once... 1 Answer
Make Bumper Effect 0 Answers
Exploide GameObjects Into BrokenParts : Unity 1 Answer
Stop a rotating plane using external force 1 Answer
A node in a childnode? 1 Answer