How do I get the rotation difference between two models?

Hey guys, I’m trying to work on a Sentry that uses tween to adjust it’s main tower’s rotation, but I realized that the speed parameter does not take into cosinderation how much the turret is gonna have to rotate.

For example, the rotation speed is 0.25 seconds, and it would take the same time to do a 360 as it would take to turn just 5 degrees.

Do you guys have an idea how I could go around this?

2 Likes

You should use lerping for this.

That could probably solve the issue now that I think about it, do you know how to Lerp a Weld CFrame while using lookAt? I tried and had no idea so I just decided to use tweenService

When using tween service, you should always use the formula time = distance/velocity.
For your case, you should do something along the lines of:

local rotation1 = model1.Orientation
local rotation2 = model2.Orientation
local displacement = (rotation1 - rotation2 ).Magnitude
local velocity = 180 -- 180 degrees a second
local t = displacement/velocty -- time

Edit: you actually cant get the magnitude of a cframe like that so you should look at the vector3 orientations. If they are actual models, you can look at the Origin Orientation property.

2 Likes

Thanks! I’ll give this a try later today

I figured out how to do CFrame Lerping with the lookAt function, which basically fixed the issue that I had.
Here’s the code that I’ve wrote to accomplish this:

local weld = mainControlWeld;
	
local lookAt = CFrame.lookAt(weld.Part1.Position+weld.C1.Position, targetPos);
rotationOffset = rotationOffset:Lerp(weld.Part0.CFrame:ToObjectSpace(lookAt), 0.1);
	
weld.C0 = rotationOffset;