So i have a Gun NPC, they shoot bullets on the target. but the problem is it stops on that position, like it doesn’t go further. how do i make it so IT goes to the position but go further.
Can you show the code you currently have?
Sure,
local distance = (target.HumanoidRootPart.Position - towertorso.Position).Magnitude
-- print(distance / 100)
local tweenInfo = TweenInfo.new(
distance / 200, --Time
Enum.EasingStyle.Linear, --Easing Style
Enum.EasingDirection.Out, --EasingDirection
-1, --Repeat Count
false, --Reverse
0 --DelayTime
)
-- local high = script.Parent.TargetHighlight:Clone()
local tween = TweenService:Create(part, tweenInfo, {Position = target.HumanoidRootPart.Position})
part.Parent = script.Parent
part.Position = script.Parent.Barrel.Position
So uh, whats the problem???
is it just possible to make it infinitely go what direction it is currently going?
I’m still trying to figure out a way.
local distance = (target.HumanoidRootPart.Position - towertorso.Position).Magnitude
-- print(distance / 100)
local tweenInfo = TweenInfo.new(
distance / 200, --Time
Enum.EasingStyle.Linear, --Easing Style
Enum.EasingDirection.Out, --EasingDirection
-1, --Repeat Count
false, --Reverse
0
)
-- local high = script.Parent.TargetHighlight:Clone()
local tween = TweenService:Create(part, tweenInfo, {Position = target.HumanoidRootPart.Position + Vector3.new(math.huge, 0, 0)})
part.Parent = script.Parent
part.Position = script.Parent.Barrel.Position
I’m not sure if this will work.
hmmm let me try it out.
3030303030030000000000300
Nope, didn’t work. It just teleported the bullet infinitely to the void.
Do you have other solutions?
Try putting math.huge
in the different axis, I might have got my axis muddled up.
Other than that, I’m not sure.
did you tried to do this ?
{Position = target.HumanoidRootPart.Position * 1.5}
doesn’t work too. maybe because its tweening to a INFINITE void position.
no that will miss 66% of the whole time.
what features of the tween do you want that a linear velocity constraint wouldn’t work with? Or scripting it to move it’s position on every heartbeat?
Speed, Delaytime, Moving Style. Plus, its more easy to do, it justs move to the position.
But its on a firerate delay, so… i can’t really just do that.
plus, if your wondering how the tween travels, well its like (NPC.Torso - Target.Torso).magnitude / 1700 = tween time.
Unless you are making some kind of math/computer science showcase I think the solution lies in the fact that you do not actually want the bullet to go INF far since floating point numbers will flat out error at INF distance, lerping to math.huge would crumple floating point precision. Depending on the speed, discrete collision will fail before floating point precision does so your left with a couple billion units of distance to travel.
There is a maximum distance you want and you either have to find it, or let the bullet move in the same direction for a limited amount of time.
You could make them overshoot the target by 2, end position at (Target.Torso - NPC.Torso) + Target.Torso
that literaly still doesn’t do anything
Try this, instead of finding the distance between objects it gets the direction to move towards the target and always moves 10,000 units towards and/or through them. And if it doesn’t work please explain why/how
local distance = 10_000
local tweenInfo = TweenInfo.new(
distance / 200, --Time
Enum.EasingStyle.Linear, --Easing Style
Enum.EasingDirection.Out, --EasingDirection
-1, --Repeat Count
false, --Reverse
0 --DelayTime
)
local diff: Vector3 = target.HumanoidRootPart.Position - towertorso.Position
local endPos: Vector3 = diff.Unit * distance
-- local high = script.Parent.TargetHighlight:Clone()
local tween = TweenService:Create(part, tweenInfo, {Position = endPos})
part.Parent = script.Parent
part.Position = script.Parent.Barrel.Position
It works, but how do you make the projectile speed faster???
lower the amount of time the tween runs for. right now it is distance / 200
which reduces to 50 seconds