local function GetStrafePosition()
local Direction = (HRP.Position - NPCHRP.Position)
local StrafePosition = HRP.Position + Direction * StrafeDistance
return StrafePosition
end
I tried to pass this function in my pathfinding and it’s returning some position god knows where, in some unobtainable position on the other side of the map.
I’m just stumped. Any help would be appreciated. Thanks.
local function GetStrafePosition()
--[[local Direction = (HRP.Position - NPCHRP.Position)
local StrafePosition = HRP.Position + Direction * StrafeDistance
return StrafePosition]]--
local StrafeRR = SharedLib:CastRay(HRP.Position, NPCHRP.Position, 15, {Player.Character})
if StrafeRR then
print(StrafeRR.Position)
return StrafeRR.Position
elseif StrafeRR == nil then
print('Couldnt cast ray?')
end
end
function SharedLib:CastRay(StartPoint, EndPoint, MaxDistance, IgnoreList)
local Params = RaycastParams.new()
if IgnoreList ~= nil then
Params.FilterDescendantsInstances = {IgnoreList}
end
Params.FilterType = Enum.RaycastFilterType.Blacklist
local Direction = EndPoint - StartPoint
local RaycastResult = workspace:Raycast(StartPoint, (StartPoint - EndPoint).Unit*-MaxDistance, Params)
return RaycastResult
end
local Direction = (EndPoint - StartPoint).Unit -- gives a direction going 1 stud
local RaycastResult = workspace:Raycast(StartPoint, Direction * MaxDistance, Params)
and also multiply your Direction by a non negative number or it goes backwards
Perhaps you want to use a magnitude check to make sure that NPCHRP.Position is within 15 studs of your character, or your ray will return nil because its too far. For testing purposes, try making MaxDistance 1000.
It returns a position if I set the maxdistance to 1000, but doesn’t this defeat the point? I’m attempting to get the position 15 studs away from the player, not 1000.
That is why it is for testing purposes. We made maxdistance 1000 to see if it gets a position and since it does, change it back to 15. The only option i can think of now is that you print the magnitude between the two positions
The magnitude between the two positions will be greater than 15. I’m attempting to move it to that position, not check if it’s already at that position.
Direction = (CFrame.lookAt(HumaniodRoot.Position, NPCRoot.Position) * CFrame.new(0, 0, -15)).Position Could work too, but im unsure about the question too.
No. The direction that the player is facing is irrelevant. Basically you’re taking the direction TO the NPC from the player’s character, then getting 15 studs along that “line” of direction.