Turning a part linearly using a body angular velocity until it faces a point

I have a part, which tries to align itself with a targets position
The turning is done via a body angular velocity.
I need to determine whether the part needs to turn left or right (all this is done on a consistent Y level)

Blue line represents parts heading
Orange line represents the heading from part to the target (assuming that (target.position - part.position).unit is how you get that)

Assuming that (Target.Position - Part.Position).Unit is correct, how do I find angle x?
Then, if angle x is above a threshold, I can let the BAV turn until the angle matches.

Furthermore, how would I differentiate this scenario and this one:
image
To then determine whether part needs to swivel left or right (first image part needs to turn right, second image part needs to turn left)

I think the action you’re trying to do can be done by using CFrame.LookAt()

Using the dot product I have found this:


This returns the value 1


This returns the value 0.75


This returns 0

Everything past this (as part continues to rotate left) just goes -0.25, -0.75 then -1.

The problem with this is that when the part turns right, the values are the same, so this cant be used to determine whether the target is overall left of the parts heading, or right of the parts heading.
This is necessary, as if the part is overall left, we need to swivel left and vice versa.

Thanks for the reply, I’ll try this:
Using that function to look at the target, then comparing that returned CFrame with the parts CFrame, and seeing whether the Y component has gotten bigger/smaller

Figured it out:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.