How do i tween CFrame.lookat()

Hi im making a tower defense game, and i want to tween the cframe.lookat()
how do i do this easily?

Simple

local Tween = TweenService:Create(Part, TweenInfo.new(1), {CFrame = CFrame.lookAt(pos, lookAt})
Tween:Play()

yeah, but now it now turns only a single itch of it. not the whole.

works for me (I used Roblox Recorder instead of other)

yeah, but maybe make it only the cframe change and not the position/rotation?

CFrame is both Position and Orientation
Screenshot (153)

now it says unable cast to dictionary.

-- ROTATION LINE STARTS HERE
	local at = script.Parent.HumanoidRootPart.Position
	local lookAt = node.Position

	
	lookAt = Vector3.new(lookAt.X, at.Y, lookAt.Z)
	local Tween3 = TweenService:Create(script.Parent.PrimaryPart, ti, {CFrame.lookAt(at, lookAt)})
    Tween3:Play()
	--script.Parent.PrimaryPart.CFrame = CFrame.lookAt(at, lookAt)	
	-- ROTATION LINE ENDS HERE

this is the problem, as u see im trying to make zombies turn at nodes smoothly.

Forgot the CFrame =

local Tween3 = TweenService:Create(script.Parent.PrimaryPart, ti, {Cframe = CFrame.lookAt(at, lookAt)})

it still not rotating smoothly

idk how

The best option is to get angle beetween two vectors, and then tween it, use the vector:Angle() function you need to do this:

A:Angle(B,Vector3.FromAxis(Enum.Axis.Y)) -- for example it gives the angle beetween two positions in Y axis

thats actually not a bad idea!

if you using object space use vector:Angle
if you using world space use this:

	local diff = (A-B)
	local angle = math.atan2(diff.X,diff.Z) * (180/math.pi)
	```

so Angle() is just a smooth tween cframe function?

not yet, but it’s calculates angle beetween two parts, if you have angle beetween two parts you can easily tween them by orientation

alr ill try.
im hoping it works

1 Like