Hello, I am wondering how I can add gravity and max distance to a raycast using the workspace:Raycast(). Thanks!

2 Likes

The max distance of the raycast is the magnitude (length) of the second direction vector. Gravity though is a bit more complicated, you would probably want to look into bézier curves.

2 Likes

** Read post below **

Alright, I’ve done this but it’s not realistic and it’s not using physics. (For context I am trying to make a baseball that sinks and when you hit it it will go flying.) My code is below.

```
function lerp(p0,p1,t)
return p0*(1-t) + p1 * t
end
function quad(p0,p1,p2, t)
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)
return quad
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, mouseHit, hrPos)
local start = hrPos + Vector3.new(0,0,3)
local finish = mouseHit.Position
local middle = (finish - start) + Vector3.new(0,30,0)
local baseBall = game.ReplicatedStorage.BaseBall:Clone()
baseBall.Parent = workspace
for i = 1, 100 do
local t = i/30
local updated = quad(start,middle,finish,t)
baseBall.Position = updated
wait(0.01)
end
wait(2)
baseBall:Destroy()
end)```
```

I have just found a tutorial and it showed me exactly what I was looking for, thanks for your help though as I may use that info in the near future!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.