Hi so I am trying to make a npc tween to a position having 1 tween tweening the angle and the other tweening the position. How can I play these 2 tweens without creating conflict between these 2 tweens
The issue is that when I play the tween that changes the orientation of the npc, that works. But then when I play another tween which is supposed to change the characters position it overides the first tween, which means it stops tweening the orientation and only tweens the position. I am basically tweening 2 cframes at the same time. A way of thinking of it is that the first tween is tweening the orientation of the npc, and the second tweens the position. Now you might wonder why I don’t have it in 1 tween, and that is because I want it to change its angle faster then its position.
If there is a way to not use cframes that is fine, but I tried using position and orientation values instead but nothing happens. I think maybe orientation is deprecated or something.
local angleCF = CFrame.new(charPos) * CFrame.Angles(0,y,0)
local posCF = CFrame.new(targetPos)
local tween1 = tweenService:Create(char.HumanoidRootPart, TweenInfo.new(.5, Enum.EasingStyle.Linear), {CFrame = angleCF})
tween1:Play()
--tween pos
local tween2 = tweenService:Create(char.HumanoidRootPart, TweenInfo.new(travelSpeed, Enum.EasingStyle.Linear), {CFrame = posCF})
tween2:Play()
tween1.Completed:Wait()
tween2.Completed:Wait()
I missed some details in my first reply
To change the position and orientation at the same time, but whereas the orientation should change at a different pace, you can use Lerp(). GnomeCode made a good video on that: Lerping - How To Move Parts Without TweenService - YouTube
If you just need to wait until two tweens are finished, do it using a ‘while’ loop as an option
local CDTween1 = false
local CDTween2 = false
local angleCF = CFrame.new(charPos) * CFrame.Angles(0,y,0)
local posCF = CFrame.new(targetPos)
local tween1 = tweenService:Create(char.HumanoidRootPart, TweenInfo.new(.5, Enum.EasingStyle.Linear), {CFrame = angleCF})
tween1:Play()
--tween pos
local tween2 = tweenService:Create(char.HumanoidRootPart, TweenInfo.new(travelSpeed, Enum.EasingStyle.Linear), {CFrame = posCF})
tween2:Play()
tween1.Completed:Connect(function()
CDTween1 = true
end)
tween2.Completed:Connect(function()
CDTween2 = true
end)
while wait() do
if CDTween1 == true and CDTween2 == true then
break
end
end
This is one of the options you can use with tweens.
It looks like you want to tween both the orientation and position of an NPC separately, with the orientation tween happening faster than the position tween. The issue you’re facing is that when you play the second tween (position), it overrides the first tween (orientation). To solve this problem, you can use separate parts to handle the orientation and position, and then combine them into the NPC’s final CFrame. Here’s how you can do it:
– Define the target orientation and position
local targetOrientation = CFrame.Angles(0, y, 0) – Adjust the angle as needed
local targetPosition = CFrame.new(targetPos)
Hi yeah thats in essence what I currently doing but its causing the rotation to last very long because I am tweening to a position and I want it to turn faster.
Yeah so thanks for all the suggestions guys, I figured it would be best to just implement my own tweening system. But I actually figured a more efficent way for me. What I did was just make the character stop moving and rotate first. And I only rotated the character when the angle was higher then .1 radians. Otherwise I just tweened the position. I think if you wanne have 2 tweens running at the same time you will need to make your own system with lerp().