Hi, I’m trying to make projectiles go up any incline/wedge while sticking to the ground. This is what I have:
remote.OnClientEvent:Connect(function(character)
local hrp = character.HumanoidRootPart
local travelTime = 0.5
for i = -4, 4 do
local part = Instance.new(“Part”, workspace.Thrown)
part.Color = Color3.new(0.0352941, 0.537255, 0.811765)
part.Material = Enum.Material.Neon
part.Size = Vector3.new(22, 1, 2)
part.CanCollide = false
part.CanQuery = false
part.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(100 / 8 * i), 0) - Vector3.new(0,
hrp.Parent.Humanoid.HipHeight + hrp.Size.Y - 0.1, 0)
local initialPosition = part.Position
local finalPosition = part.Position + part.CFrame.LookVector * 100
local t = 0
local moving
local direction = part.CFrame.LookVector
local function adjustTrajectory(part)
local rayDirection = part.CFrame.LookVector * 2
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.Thrown, character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(part.Position, rayDirection, raycastParams)
if result then
local normal = result.Normal.Unit
local reflection = direction - 2 * direction:Dot(normal) * normal
direction = reflection.Unit
local distanceTraveled = (part.Position - initialPosition).Magnitude
finalPosition = part.Position + direction * (100 - distanceTraveled)
end
return
end
moving = runService.RenderStepped:Connect(function(delta)
t += delta
adjustTrajectory(part)
part.Position = initialPosition:Lerp(finalPosition, t / travelTime)
if t >= travelTime then
moving:Disconnect()
end
end)
end
end)
I have tried using the angle between vectors formula like this but to no avail:
if result then
local normal = result.Normal.Unit
local reflection = direction - 2 * direction:Dot(normal) * normal
direction = reflection.Unit
local theta = math.acos(direction:Dot(normal))
local distanceTraveled = (finalPosition - initialPosition).Magnitude
finalPosition = part.Position + part.CFrame.LookVector * (100 - distanceTraveled)
end
I’d appreciate any help.