This yellow target is supposed to follow your character using TweenService to make it move smoothly and with a small delay.
Unfortunately, as shown in the video, this isn’t the case and the target flies off.
local TweenService = game:GetService("TweenService")
local r_service = game:GetService("RunService")
function trace()
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0.1)
local newPos = {Position = bomb.Position + Vector3.new(bomb.Target.Value.Position.X, bomb.Position.Y, bomb.Target.Value.Position.Z)}
local move = TweenService:Create(script.Parent, tweenInfo, newPos)
move:Play()
end
t, s = r_service.Stepped:Wait()
d = t + 2 - s
while t < d do
print(t)
print(d)
t = r_service.Stepped:Wait()
trace()
end
Well, that might indeed be one of the reasons to do it a different way. Therefore, I wanted to try Tweening (as shown in my first message). Happen to know what’s causing the target to fly off like that?
As mentioned, just changing the position results in slow and faltering movement, especially when you try and create a delay using wait(x) yourself.
This is exactly why I was looking for a different way of movement, being TweenService.
After trying that, the target appears to move smoothly, but somehow does not follow my character and instead flies off.
I am looking for a solution for this fly-away behaviour.
TweenService is the smoothest you’ll get on the server, RenderStepped being the exact same.
I don’t know if that’s what causes the problem, but the way your code is structured it won’t work as expected either way.
You create a 1-second-long tween:
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0.1)
and then repeat it every 1/30th of a second:
while t < d do
r_service.Stepped:Wait()
I’m not sure if TweenService is the right approach here at all. If you want to use it, try stopping each tween at the beginning of the loop.
Constantly creating a new tween isn’t the best way to get smooth movement.
Instead set the position yourself to the goal of the tween. It will be as smooth as your character if you BindToRenderStep instead of using a while loop and waiting for the step to finish.
If you do want the target to lag behind, then you can implement some of the tweening functions yourself in the BindToRenderStep connection.
function easeOutQuad( alpha )
return 1 - (1 - alpha) * (1 - alpha)
end
game:GetService( 'RunService' ):BindToRenderStep ( 'TargetTrace', 201, function ( deltaTime )
local alpha = 2 * deltaTime -- tweak to whatever number you want for smoothness
script.Parent.Position = script.Parent.Position + directionTowardsGoal * easeOutQuad( alpha )
end )
Where directionTowardsGoal is equal to goalPosition - script.Parent.Position. I assume the goal is the character but I couldn’t see anything about the character in your original post.
I managed to fix the main problem, being the target flying off, myself.
local newPos = {Position = bomb.Position + Vector3.new(bomb.Target.Value.Position.X, bomb.Position.Y, bomb.Target.Value.Position.Z)}
In this line, it basically took the current position (100, 5, 100) for example and added the Root’s position, giving a position of (300, 5, -20) for example.
Thank you for your time and replies. I will try and work with your suggestions on how to make the target move more efficient now.