You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I want to predict where shoot a moving target while accounting for drop. -
What is the issue?
I have a script calculating where to shoot to hit a moving target and at the moment it works perfectly fine, until I put bullet drop into the equation. I already have a fairly good idea why this is. Instead of dropping my bullet down x studs every renderstep, I just move the direction of the line the bullet travels on downwards x studs. This causes the shoot position to be off, as my equation for adding drop is wrong.Without drop:
https://gyazo.com/89f30ae5434cb57e058b1072abfd852fWith drop:
https://gyazo.com/b08aae95aa600c265250982dd0346615 -
What solutions have you tried so far?
Really, I am pretty clueless with this one, as I can not construct an equation that represents how many studs the bullet is doing to drop over the amount of time it takes to reach the target. I have tried reworking the equation many times over, but to no avail.
-
Additional Resources
The way my bullets travel:
local drop = Vector3.new(0, (stats.Drop / 100) * margin, 0) --stats is just a modulescript with gun statistics, in the gif the stats.drop was .2
local aim = (CFrame.new(start.Position, target) * CFrame.Angles(math.rad(spreadx), math.rad(spready), 0)).LookVector --spread was off for the test of course
game:GetService("RunService").RenderStepped:Connect(function(last)
local margin = last * 60
local pos = aim * (margin * Velocity)
bullet.CFrame = CFrame.new(bullet.Position + pos, (bullet.Position + pos) + pos.Unit)
aim = aim - drop --ignore the 10000 parentheses, its just an organization problem
end)
--this was just snippets put together of the actual script i made, but should be all you need
How I calculate where to shoot:
local Target = thing:WaitForChild("Target") --what its supposed to hit
local Marker = Target:Clone() --where to shoot
local Shooter = thing:WaitForChild("shooter") --where it shoots from
Marker.Color = Color3.fromRGB(255, 0, 0)
Marker.Name = "Marker"
Marker.Parent = thing
local bulletStart = Shooter.Position
local bulletspeed = 2
local drop = .2
local last = Target.Position
Target:GetPropertyChangedSignal("Position"):Connect(function()
local speed = (Target.Position - last).Magnitude
local direction = (Target.Position - last).Unit
local offset = (bulletStart - Target.Position).Magnitude
local timetotake = offset / bulletspeed
local dropoffset = Vector3.new(0, (drop * timetotake), 0) --wrong
Marker.Position = (Target.Position + (direction * (speed * timetotake))) + dropoffset
last = Target.Position
end)
Any help is greatly appreciated.