How do you check if a character's torso is facing the direction of a part? (or vice versa)

Sypnosis
Hello, this is the Almigthy Jlamtt.

screenshot 23

I am trying to make a mechanism where when the character move towards the direction of Jlamtt, the character gets slower the closer they get.
Hence, I am planning on loop getting the players’ distance and set their WalkSpeed depending on how near they are.

The Problem
At some point, the character’s WalkSpeed will reach 0 when getting too near to Jlamtt. The thing is, I want the character to be able to walk when facing the opposite direction of the Almighty Jlamtt. I would just have to set the WalkSpeed to 1 when the character’s torso is facing the opposite direction of Jlamtt, but I don’t know how to check if the character’s torso is facing the opposite of Almighty Jlamtt.

The Question
How do you check if a character’s torso is facing the opposite direction of Jlamtt?
I would like to check if the character’s torso is facing the whole opposite axis of Jlamtt, not just facing the exact opposite of Jlamtt’s primary part.

By the ‘whole opposite axis of Jlamtt’, do you mean this?

1 Like

Yes, that’s right! I want to check if the torso is facing anywhere between that 180*.

To see which way the player is facing, you can use player.Character.UpperTorso.CFrame.LookVector
and to see which way a part is facing, you can do like the same thing: workspace.Part.CFrame.LookVector

So what you can do is store the player lookvector in a variable and type Variable = Variable - (Variable * 2) to just make the variable negative. Then you can subtract or add (idrk) the two look vectors.

Hope this helped.

1 Like

I thought about LookVector, but I want for the character to face the whole opposite 180* of Jlamtt, basically facing the opposite axis. Nevertheless, I assume LookVector only works for specific face direction.

1 Like

I believe using :Dot would help achieve this. With this you can tell if they are facing it. If you combine that with .Magnitude and some type of formula to do the walkspeed it should work.

Here is a good tutorial on :Dot

There’s a variety of ways to accomplish your achievement, but I would use the dot product in this case.


(Click this for high resolution image)

Let me know if you have any point confusing

1 Like

could you explain how |T| = |J| = 1?

Since T and J are set as unit vector in the graph above, magnitudes of T and J are supposed to be both 1

1 Like