What would be an effective way of visualizing each raycast without a result?

What would be a way to visualize each individual raycast here if no result is given (the “bullet” is still in the air)

For context, here are the start values of self._AgentPosition and self._AgentVelocity. “workspace.Part” is just a random, anchored part in workspace.

_AgentPosition = workspace.Part.Position
_AgentVelocity = workspace.Part.CFrame.LookVector * 100
return Promise.Async(function(resolve, reject)
	local startTime = tick()
	while true do
		local deltaTime = game:GetService("RunService").RenderStepped:Wait()				
		local raycastResult = workspace:Raycast(self._AgentPosition, self._AgentVelocity, self._IgnoreList)

		if raycastResult then
			resolve(raycastResult.Instance)
			return
		else
			self._AgentVelocity = self._AgentVelocity - (Vector3.new(0, workspace.Gravity, 0) * deltaTime)
			self._AgentPosition = self._AgentPosition + self._AgentVelocity * deltaTime	
		end
	end	
end)

Scratch that – I was able to visualize the raycast. However, it seems to be returning a raycast result before the rays actually touch the baseplate. Notice how “Baseplate” appears in the console before the parts actually reach the baseplate. (You might have to slow it down a little)

Whats going on here is that then you multiply the lookvector by 100, its actually setting the raycast distance to 100. So the ray would hit the baseplate before the part does.

You should divide the raycast by something like 20, so the raycast hits the baseplate when the part does.

-- here the direction of the raycast is divided by 20, so the range of the raycast is 5.
local raycastResult = workspace:Raycast(self._AgentPosition, self._AgentVelocity / 20, self._IgnoreList)
2 Likes

You are absolutely right, thank you.