I’m trying to tween one player 5 studs infront of another player, and make them face eachother.
The problem with this, is it keeps tweening the player to move a couple studs higher, and I keep trying to change it but then it either doesn’t work or the orientation doesn’t tween.
local infront = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * Vector3.new(5, 0, 5)
local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, false)
local lookat = CFrame.lookAt(target.Character.HumanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)
local pos = infront * lookat
local position = CFrame.new(pos.Position.X, plr.Character.HumanoidRootPart.Position.Y, pos.Position.Z) * CFrame.Angles(pos.Rotation.X, pos.Rotation.Y, pos.Rotation.Z)
local a = tweens:Create(target.Character.HumanoidRootPart, tweenInfo, position):Play()
This script doesn’t work btw, this is giving the error “Unable to cast to Dictionary”
local position = CFrame.new(pos.Position.X, plr.Character.HumanoidRootPart.Position.Y, pos.Position.Z) * pos.Rotation
Tween goals are dictionaries, you’re getting an error because you’re just passing position (a CFrame value) and the tween doesn’t know property to apply that CFrame to. Here is a proper way to create the tween:
local goal = {CFrame = position}
local a = tweens:Create(target.Character.HumanoidRootPart, tweenInfo, goal):Play()
Thanks for this, I wasn’t too sure what that error meant but now I understand.
Now, my problem is I want to get the target to face the player whilst moving to them with the tween.
local infront = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 5
local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, false)
local position = {CFrame = infront}
local a = tweens:Create(target.Character.HumanoidRootPart, tweenInfo, position):Play()
Since tweening them to infront already makes them face the same direction as me, how would I reverse this direction, since that seems like this is the best option to me.
Since the final cframe is the plr’s cframe with a forward offset you should be able to rotate it 180 degrees along one axis, I believe something like this will work:
-- might need to switch which axis (XYZ) math.pi is on
local position = {CFrame = infront * CFrame.Angles(math.pi, 0, 0)}
Okay that worked thank you so much! But if you don’t mind, can you explain to me what math.pi is doing to make it work here? Seems like magic to me lol
Sure thing! CFrame.Angles is in radians (0 - 2pi), which I’m just going to lazily summarize as a unit in rotation and trigonomtry as opposed to degrees (0-360 degrees). A full 360 degree rotation in radians is 2*pi, so a 180 degree rotation is 1 pi. math.pi == math.rad(180) math.deg(math.pi) == 180