Using Ray To Find Points Sometimes WAAAAAAAAY Off


The topic may seem exaggerated but I’m lost in this code at the moment. I have created a segment of code that handles manipulating a player and their target in a combat sequence to push both players up at an angle then send the target back down at an angle. Here is the code created to handle this effect:

local ORIGIN = Char.HumanoidRootPart.CFrame
local TARGETA = ORIGIN*,20,-30)
local TARGETB = ORIGIN*,22,-28)
local TARGETC = ORIGIN*,0,-60)
local IgnoreList = {Char,HRP.Parent}
local RAYA =,TARGETA.p)
local HITA,HITPOSA = workspace:FindPartOnRayWithIgnoreList(RAYA,IgnoreList)
if HITA then
	TARGETA =,,RAYA.Direction).LookVector)
local RAYB =,TARGETB.p)
local HITB,HITPOSB = workspace:FindPartOnRayWithIgnoreList(RAYB,IgnoreList)
if HITB then
	TARGETB =,,RAYB.Direction).LookVector)
for i=0,1,.1 do
	HRP.CFrame = HRP.CFrame:Lerp(TARGETA,i)
HRP.Anchored = true
for i=0,1,.1 do
	Char.HumanoidRootPart.CFrame = Char.HumanoidRootPart.CFrame:Lerp(TARGETB,i) --TARGET2??
Char.HumanoidRootPart.Anchored = true
local RAYC =,TARGETC.p)
local HITC,HITPOSC = workspace:FindPartOnRayWithIgnoreList(RAYC,IgnoreList)
if HITC then
	TARGETC =,,RAYC.Direction).LookVector)
HRP.Anchored = false
Char.HumanoidRootPart.Anchored = false
for i=0,1,.1 do
	HRP.CFrame = HRP.CFrame:Lerp(TARGETC,i)

In this code, the two identified objects is the using player’s character (Char) and the target player’s character (HRP.Parent). ORIGIN is the using player’s character, TARGETA is the destination prior to casting a ray to define a point not obstructed, TARGETB does the same for the path of the character, and TARGETC is the point land the enemy character.

This code runs fairly well, except there are times when TARGETA/TARGETB are no longer within the defined boundaries and send the user and target over 2,000 studs in the facing direction.

Let me know if you see any issues with my current handling that I can improve on to remove this inconsistency. Also, if you have a suggestion on a different way of handling this type of action please let me know. I have tried lerping, tweening, body movers, and other variants utilizing raycasting and each seems to have a positive and negative to it… The lerping is the closest I have gotten to perfect handling, aside from this very random occurrence…


Forgive me for skimming, I don’t get paid.
TARGETB = ORIGIN*,22,-28) uses origin and direction, not origin and target. Unless I’m incorrect about your actual problem, you should use this instead., targetb.p-origin.p)
Also pardon capitalization, I’m on mobile. Let me know if this doesn’t fix it.

1 Like

You are absolutely right! Thanks man, as of now it is working flawlessly. I have no idea why I thought it was origin and target… Thanks!!

1 Like

Everyone thinks that at first. I suppose it makes a lot of sense to most people, and whenever someone has a ray issue it is the first thing I look for. Good luck with the scripting.