how can I calculate the exact amount of distance something will travel based on their velocity?
Velocity = distance / time
Therefore, if you know time and velocity, you can find distance.
Distance = velocity * time
Units:
Velocity (studs per second)
Distance (studs)
Time (seconds)
you can use object.AssemblyLinearVelocity.Magnitude to get the speed of the object, then multiply that value by the amount of time to see how far it’ll travel in the allocated time
Do you mean something affected by gravity? EgoMoose has an article on modeling projectile motion here:
If there isn’t gravity you can just use a single raycast.
If you don’t want to model projectile motion just use velocity * time.
Velocity is already in studs, and measures how much an object’s position will change every second.
If you want to get how far an object will travel in X amount of time, you can do the following:
local function getChangeInDistance(velocity: Vector3, seconds: number): Vector3
return velocity * seconds
end
-- now, print the estimated change in position of 'Part' in 0.5 seconds
print(getChangeInDistance(workspace.Part, 0.5))
One caveat is that velocity usually changes all the time due to gravity. You can view the reply above me if you want to counteract the effects of that.