I highly appreciate anyone who has the time to read my forum post, as I’ve been struggling for a while in this certain topic: Getting the impact position of a projectile with nothing but Initial Position, and Projectile Velocity.
Now; incase that’s impossible, I just wanted to know if there is an effective way to determine where a projectile will hit. Projectile is affected by gravity, and it fires the projectile towards the mouse.hit.position ( CFrame.new(Position, mouse.hit.position) )
If you have any suggestions or ideas, it’ll be greatly appreciated!
Why would you need to figure that out? I’m guessing you’re making some hitreg system of sorts, but I don’t understand why you’d need to figure out a projectile’s landing position ahead of time.
If you have a lot of moving parts, it can be tricky to determine where they’ll be ahead of time, meaning it can be difficult to predict when a moving object might suddenly get in the way of your projectile.
This is especially the case with players - you can’t predict where a player will move ahead of time.
That’s no problem at all! Right now, I wanted to show a part that is positioned to where the projectile impacts… I do understand what you mean, which is why I’d like to mention that the trajectory will constantly update every moment prior to a frame (renderstepped).
If you’re into planes, then you might’ve heard of something called a Constantly Computed Impact Point (CCIP) which shows the impact of your munition on digital terrain surface, as objects such as buildings arent taken account for in the digital map.
The variables for the x are: u (the initial speed), and t (time) so it is s = v₀t
The variables for the y are: u (the initial speed), a (gravity of the place), and t (time)
local function simulateProjectilePath(firingPosition, firingVelocity)
local gravity = Vector3.new(0, -196.2, 0) -- Roblox gravity
local timeStep = 0.05 -- Time step for simulation in seconds, smaller for more accuracy
local totalTime = 0 -- Total simulation time
local currentPosition = firingPosition
local currentVelocity = firingVelocity -- Now a Vector3 value
local raycastParams = RaycastParams.new()
raycastParams.IgnoreWater = true -- Customize as needed
raycastParams.FilterDescendantsInstances = {} -- Objects you want to include here. You can change the filtertype if you want.
raycastParams.FilterType = Enum.RaycastFilterType.Include
while true do
-- Calculate the new position based on current velocity and gravity
local newPosition = currentPosition + currentVelocity * timeStep + 0.5 * gravity * timeStep^2
local direction = newPosition - currentPosition -- The direction and distance for the raycast
local raycastResult = workspace:Raycast(currentPosition, direction, raycastParams)
if raycastResult then
-- Hit detected, place your target indicator here
--print("Hit at: ", raycastResult.Position)
-- Place target indicator logic here, e.g., creating a part or marker at raycastResult.Position
return raycastResult.Position,raycastResult,totalTime -- Returning the hit position
end
-- Update for next iteration
currentPosition = newPosition
currentVelocity = currentVelocity + gravity * timeStep -- Update velocity with gravity
totalTime = totalTime + timeStep
-- Optional: Stop simulation after a certain time to prevent infinite loop
if totalTime > 10 then -- Adjust as necessary
--print("No hit detected within simulation time.")
break
end
end
return nil --
end
return simulateProjectilePath