#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# How to move a rigid body 2d??

Member

Hey all.. I want help to move a rigid body 2d towards a specific position..

And if it reaches the position it should be going in that direction..

I'm currently working on a top down circle game.. But don't know how to move it towards a position and let it going..

Pls help

• Member
edited May 2020

You could create a vector between the two points, normalize it, and set it as the velocity of the gameobject you want to move. I'm pretty sure there's also something called MoveTowards, which should work until the destination is reached.

• Member

But @Sander it will only move towards that point and stop there it will not go further than that point...

Btw thnks for ur suggestion...

• Member

You can add force like this

Vector3 inputDirection = "your direction, you can use mouse point or whatever"

float thrust = Vector3.Dot(inputDirection.normalized, this.transform.forward);

this.rigidbody.AddForce(thrust * inputDirection.magnitude *this.transform.forward * velocity * Time.deltaTime);

• Member

As long as you save the vector, and use it as the velocity, it will move past it.

• Member
edited May 2020

try using " [Rigid Body reference] .movePosition( [targeted Position] )"

then by subtracting your target position from your position you will get a vector2 that is in the direction of your target position.

it will look like this :

Vector3 direction = [your target transform] .position - transform.position;

[Rigid Body Reference] .movePosition( [your target transform] .position);

if ( [your way to detect if it does reach our targeted position or not ] ) { *

[rigid body reference] .movePosition( transform.position + direction.Normalized );

}

• you can remove If statement if you want it to always move in that direction.

i hope that helped ;)