How to get direction that someone is moving in relation to a part?

I know that it is possible to get the moving direction of a player through various ways but how would I be able to get it based on a part like to the left of the part might be going forward for the player but I want to find out if its left. If this doesnt make sense read below.

I want to get the direction of a player compared to a part.

Can you maybe give us the situation and the expected output you require?
Something like "I’m making a traffic signal and want to know if a player is going to the left or right of it’ or a similar description.

Im pretty sure I made that clear.

I want to get the direction the player is moving compared to a part.

What you said wasn’t clear, as I had already written you this:

removed: GL

which is different to what you have now asked for.

When you’re asking for help, it’s best to be as clear as possible and appreciative of those who are asking for clarity when they’re the ones who will be helping you :slight_smile: @Scottifly was right to ask you to clarify considering the above

I said I want the direction a player is moving compared to a part. Not trying to be rude but that is very clearly stated in my original post.

It’s still not, sadly. Your OP and what you’re asking for are two different things. Your first post asks how to determine whether a part is to the left of another object, your comment asks for the delta direction a player is moving relative to a part which is a different thing.

As scottify asked, can you tell us what your end goal for this is e.g. an example application? Are you trying to determine if a player is currently moving left relative to a part? Or if at that moment they are currently to the left of a part? etc

1 Like

In my reply I said “I want to get the direction the player is moving compared to a part.”

In my original post I specifically said “I want to get the direction of a player compared to a part.”

For your second question

I have a part in the middle of my game and I am trying to tell which way they are moving compared to the part. Like if you have a hoop in basketball. I am trying to tell if you are running towards the hoop.

1 Like

Normally I post code replies, but instead I feel it may be best to give you an explanation in this circumstance.

Assuming you want this as a delta, the simplest and fastest method would be to derive the squared distance between both vectors, in this case, the vector Q for the player and vector P for the hoop. On each step of the frame at whatever granularity you require for your application, derive the delta using the last frame’s squared distance. If the distance is less than it previously was, you are closer to the hoop. -ve values would be moving towards the hoop, +ve values would be away from the hoop.

If you require greater precision, get the magnitude of those vectors.

However, if you require positional information e.g. ‘to the left’, you would need to use similar to code as I described above, which derived the positional data by getting the relative position of the player to the part.

1 Like
(game.Workspace.Hoop.CFrame:inverse()*CFrame.new(Vector3.new(0,-1,0),char.Humanoid.MoveDirection)).LookVector

Worked for me if anyone is looking at this later on.