So I want to make a knockback that follows an arc and gets reflected appropriatly when it hits an obstacle. To do the arc I used this guide from EgoMoose: https://devforum.roblox.com/t/modeling-a-projectiles-motion/176677
My approach was to move the player with a bodyPosition in a loop and raycasting the path he would travel. Then when a ray hits an obstacle the “velocity” gets reflected.
For the most part it works fine, but when the “velocity” is too fast the ray does not register on the obstacle. So what I need help with is detecting the collision of the ray.
Here is an example of the problem:
Here is the main code that runs this: (Note: I left out some things like the visualization of the rays for hopefully better readability)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {target, char}
nt = 0
while (nt < t) do
local normalCast = workspace:Raycast(p0, multiplier*g*nt*nt + v0*nt, params)
if normalCast and normalCast.Instance.Parent:FindFirstChild("Humanoid") == nil and normalCast.Instance.Name ~= "HitBox" and normalCast.Instance.Parent.Name ~= "Platform" then
local newP0 = target.HumanoidRootPart.Position -- Position of the target where it hits the obstacle
local newV0 = v0 - (2 * v0:Dot(normalCast.Normal) * normalCast.Normal) -- reflect velocity
newV0 /= 2 -- lose some velocity after deflecting
self:_simulateKnockback(newP0, multiplier, g, t, newV0, target, char, bp) -- Restarts the whole thing with the updated values
return
end
bodyPos.Position = p0 + multiplier*g*nt*nt + v0*nt -- move target
nt = nt + runService.RenderStepped:Wait();
end
If you need any more info please feel free to ask