- Home /
Freeze a Rigidbody2D's constraints and move the object manually with translate/Movetowards
Hi, I haven't used Unity in over 2 years so I'm going through the basics again really, I'm trying to freeze a rigidbody's constraints using
this.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
Then after freezing the Rigidbody, in another script I'm trying to move the object manually using translate to a target, but it just pops into place rather than slowly moves to the object like I intend to do.
I'm trying to move the object using
other.transform.position = Vector2.MoveTowards (ball.transform.position, target1.position, move);
But this just pops the object to the target position without actually moving the object towards the target. I tried other ways to make the object Rigidbody2d to sleep, but this just continues to move the object's velocity right after it stops. Any methods I could use instead of this?
Answer by Lili-Shi · Oct 07, 2017 at 12:38 PM
It's actually pretty simple. You only have forgotten one thing: multiplying your move
-variable with Time.deltaTime
within the Vector2.MoveTowards
method. So it should something like this: other.transform.position = Vector2.MoveTowards (ball.transform.position, target1.position, move * Time.deltaTime);
Cheers!
Your answer
Follow this Question
Related Questions
how to jump at fixed height but faster 0 Answers
Weird Rigidbody2D.velocity.x problem, float out of control 0 Answers
2D Physics Broke 1 Answer