I have animated a bird. The script rotates the bird to a randomly chosen part node using tweenservice
After rotation, tweenservice tweens bird to node’s position + bird’s lookvector
Problem
As bird is tweened to the node’s position it slowly rotates to fixed point instead of it’s original facing direction set by the previous tweened rotation. How can I tween the bird to the node’s position and keep the facing direction.
Notes
The rotation tween changes the lookvector of bird to face the node point. It happens before the movement tween.
local function lookAt(node)
local lookV=node.Position
local cf=CFrame.new(model.PrimaryPart.Position,lookV)*CFrame.Angles(math.rad(-45),0,0)
local goal={CFrame=cf}
local tweeninfo=TweenInfo.new(1)
local tween=tweenservice:Create(model.PrimaryPart,tweeninfo,goal)
tween:Play()
tween.Completed:Wait()
end
local function moveTo(node)
local lookV=model.PrimaryPart.CFrame.lookVector
local cf=CFrame.new(node.Position,-lookV)*CFrame.Angles(math.rad(-45),0,0)
local goal={CFrame=cf}
local tweeninfo=TweenInfo.new(10)
local tween=tweenservice:Create(model.PrimaryPart,tweeninfo,goal)
tween:Play()
tween.Completed:Wait()
end
for i=1,10 do
local node=getNode()
lookAt(node)
moveTo(node)
end
local function lookAt(node)
local lookV=node.Position
local cf=CFrame.new(model.PrimaryPart.CFrame, lookV)
cf = cf *CFrame.Angles(math.rad(-45),0,0)
local goal={CFrame=cf}
local tweeninfo=TweenInfo.new(1)
local tween=tweenservice:Create(model.PrimaryPart,tweeninfo,goal)
tween:Play()
tween.Completed:Wait()
end
local function moveTo(node)
local lookV=model.PrimaryPart.CFrame.lookVector
local cf=CFrame.new(node.Position,-lookV)*CFrame.Angles(math.rad(-45),0,0)
local goal={CFrame=cf}
local tweeninfo=TweenInfo.new(10)
local tween=tweenservice:Create(model.PrimaryPart,tweeninfo,goal)
tween:Play()
tween.Completed:Wait()
end
for i=1,10 do
local node=getNode()
lookAt(node)
moveTo(node)
end
On the video, from what I can see the the bird is not looking at the node, so I automatically assumed it was because of the LookAt function. Also why not mix the functions together? They are passing the same values through.
It creates more of a realistic feel. The bird reaches a node, then turns it’s body to another node and then moves to the node. If I mixed them then the whole movement wouldn’t look as appealing. Please review the rblx file I linked or review the code snippet.
If I understand this correctly, you want to move the bird to a point while keeping its initial rotation right? Correct me if i’m wrong.
--// p0 being the 'bird', p1 being the target position
local TargetCF = (p0.CFrame + p1.CFrame.Position)-p0.CFrame.p
TweenService:Create(p0, TweenInfo.new(4), {CFrame = TargetCF}):Play();
I got your place file to work, where I made changes in the script I added a comment to the line. Also, for your bird model I hade to recreate the motor 6d’s so the animation may no longer work, the issue with the bird model is that you need to ensure that the root part is facing all the correct directions or your gonna mess up the calculations for movement, so in the properties tab, under the Surface heading, ensure front surface is facing the front of the model. If there is anymore issues let me know. animalsAnimted.rbxl (30.2 KB)
Thank you, the post above also gave me a solution. Also, the humanoidrootpart is positioned correctly. All parts connected move in relation to it so I didn’t need to re-do the rig.