I am trying to make a part that goes to the player HumanoidRootPart position at the moment, and continue going until hit a barrier. I am currently moving the part with TweenService, and I am moving to player HumanoidRootPart position, but not continuing moving in that direction. How can I do this?
-
What do you want to achieve? (aproximately)
-
Current code
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1)
local a = ts:Create(workspace.Part, ti, {Position = playerRoot.Position})
a:Play()
uhm your setting the part position at the playerRoot position, so the end result will be that the part will end up where the playerRoot is.
You can create a new TweenInfo to be executed when the position of the part is == to the playerRoot
but how to keep it going on that direction until the barrier.
The solution that I found was that:
I am making this for a boss.
I have a tween that rotate the boss to player direction.
|
|
|
local cf = CFrame.lookAt(bossHRP.Position,charHRP.Position * Vector3.new(1,0,1) + bossHRP.Position * Vector3.new(0,1,0)) |
|
|
|
local tween = ts:Create(boss.PrimaryPart, ti, {CFrame = cf}) |
And so, I created the part at the boss’ HumanoidRootPart (that was pointing to player) and set the tween to go until the arena hitbox.
|
|
|
local pos = bossHRP.CFrame + (bossHRP.CFrame.LookVector * Vector3.new(hitbox.Size.X,hitbox.Size.Y,hitbox.Size.Z)) |
|
|
|
local tween = ts:Create(Ball, ti, {CFrame = pos}) |
|
|
|
tween:Play() |
And when the tween was completed (reached the end of arena’s hitbox) I destroyed the part.
|
|
|
tween.Completed:Wait() |
|
|
|
Ball:Destroy() |
You can also use
a.Completed:Connect(function(playbackState)
if playbackState == Enum.PlaybackState.Completed then
-- Your code
end
end)
This checks when the first tweening finish so you can add another tween