How to get endpoint position of ray that has not hit?

Lets say I had a player and I cast a ray from the player, depending on the HumanoidRootPart.CFrame.lookVector how would i get the end position of the vector of the ray even if it doesn’t hit?
image

2 Likes

I’m pretty sure you can get the Position even if the Ray didnt hit anything?. try printing out the Position?

Nope attempt to index nil with 'Position'

2 Likes

Weird. Works for me. Can you show me your code??

try this:
local Raycast = Ray.new(“Start Position”, “End position”)
local Part, Position = game.Workspace:FindPartOnRayWithIgnoreList(Raycast, ignore, false, true)

local destination = plr.Character.Muzzle.CFrame.lookVector
local speed = 50
local start = plr.Character.Muzzle.Position
local destination = destination * speed
local raycastResult = workspace:Raycast(start, destination, raycastParams) -- Params is just an ignore list with new api

Can’t give whole code since its in sections though i use the new API to raycast

2 Likes

Well if you know where the ray began, it’s direction & length, then you can calculate the end position with
start + direction * length

This might sound like a stupid question i know. But are you getting the position like this: “raycastResult.Position”

Sigh, I guess i should clarify what im doing a little bit better…

Yes I’am getting the position like that

1 Like

It would be something like this, I formatted it to fit your code but I haven’t tested this.

if not raycastResult.Instance then -- Didn't hit anything
    local endPos = start + destination -- World position of where ray ended
    raycastResult = workspace:Raycast(endPos, destination, raycastParams) -- New raycast continuing from last
end

If you want more than 2 raycasts you’ll have to adapt this into a loop

1 Like

Hold on i think i got it working… Let me do some checks to see if everything works

EDIT: Thanks mate! Now i got timed bullets :slight_smile: