-
What do you want to achieve? Keep it simple and clear!
Make the missile not miss when the velocity of a target is changed. -
What is the issue? Include screenshots / videos if possible!
The missile misses when the BodyVelocity of the target changes. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for solutions on the devforum but so far no luck.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local count = false
local main = workspace.rocketthing
local RunService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
print(workspace.Part.Size.Magnitude)
function flight()
local oldVel = workspace.Part.BodyVelocity.Velocity
--print(math.floor(workspace.Part.Velocity.Magnitude + .5))
local timepassed = 0
local t = math.floor(workspace.Part.BodyVelocity.Velocity.Magnitude/50 + .5)
print(t)
local pos = workspace.Part.Position + workspace.Part.Velocity * t
local distance = (main.Position - pos).Magnitude+workspace.Part.Size.Magnitude
local speed = math.floor(distance / t) + workspace.Part.Velocity.Magnitude/15
main.CFrame = CFrame.lookAt(main.Position, pos)
while task.wait() do
--local timeInAir = math.floor(distance / speed)
--local dist = speed * timeInAir
main.CFrame = CFrame.lookAt(main.Position, pos)
local thrust = main.BodyVelocity
print(speed)
thrust.Velocity = main.Attachment.WorldCFrame.LookVector * speed
main.Touched:Connect(function(hit)
local explosion = Instance.new("Explosion")
explosion.Position = main.Position
explosion.Parent = workspace
explosion.DestroyJointRadiusPercent = 100
explosion.BlastPressure = 10000
explosion.BlastRadius = 30
print("Hit")
explosion.Hit:Connect(function(hit)
print("Hit")
if hit:IsA("BasePart") then
hit.Material = Enum.Material.CorrodedMetal
print("adding fire")
local fire = Instance.new("Fire")
fire.Size = 30
fire.Heat = 25
fire.Parent = hit
print("Fire added")
end
end)
main:Destroy()
workspace.Part:Destroy()
--script:Destroy()
end)
if workspace.Part.BodyVelocity.Velocity ~= oldVel then
print("Thing")
flight()
oldVel = workspace.Part.BodyVelocity.Velocity
break
else
oldVel = workspace.Part.BodyVelocity.Velocity
end
end
end
flight()
This is the current script I have right now.
Any help is appreciated!