Place Part In Direction Of Character Movement

I want to check which direction the player is moving and place a part in that direction.

If they move forward place a part infront of them.

If they move backward place a part behind them.

If they move leftward place a part to the left of them.

If they move rightward place a part to the right of them.

What have I tried?

I tried using movedirection, but I am confused on how I would offset the part.

I even looked on Dev Forum, but all them I found are no solution.

You’ll be using MoveDirection. MoveDirection is, as described in DevHub:

MoveDirection is a read-only property that describes the direction a Humanoid is walking in, as a unit vector or zero length vector. The direction is described in world space.

A unit vector can be used as a direction, of sorts. It is basically an offset, but think of it as a one-stud long arrow. It points in the direction of some position. In the case of MoveDirection, it points to where the player’s character will be within one stud given that they keep their current velocity.

If you add this arrow to a position, you’re going to get that same position but moved forward in the direction of the arrow. Because the unit vector is at max one stud long, you will probably find it useful to multiply by however many studs you want it to be pushed forward.

Since Vector3s can be added together, it is very simple:

part.Position = character.HumanoidRootPart.Position + humanoid.MoveDirection * 5

This would put a part at a character’s center offset by five studs into the direction that the arrow (MoveDirection) is pointing at.

I appreciate that, thank you very much!

1 Like