Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with raycasting?

Asked by 9 years ago

I'm making a script were when my AI detects a part in front of him, he jumps. Though i'm going to use raycast to do this, and i never used raycast, consequently making me not knowing exactly on how to use it. So this how i want my ray cast to look (of course i don't want the part).

http://prnt.sc/8llfmp

Though i haven't figured it out on how to do it. But here was my attempt:

local rayStart = script.Parent.Torso.Position - Vector3.new(0,3,0)
local rayLook = (rayStart - script.Parent.Torso.CFrame.lookVector*Vector3.new(0,0,5)).unit
local ray, pos = Ray.new(rayStart,(rayLook-rayStart).unit)
local partOnRay = game.Workspace:FindPartOnRay(ray,script.Parent)

Note that this is working. Though the ray is looking downwards, not forwards.

1 answer

Log in to vote
0
Answered by
KLGA 0
9 years ago

I think the problem is that you're starting at Y 3, and ending it at Y 0, You should do either of the below, I'm not sure which, sorry. But I think by multiplying it by 0, you're getting zero. So try 1. If 1 doesn't work, try 3.

local rayLook = (rayStart - script.Parent.Torso.CFrame.lookVector*Vector3.new(0,1,5)).unit

Try this if the above doesn't work:

local rayLook = (rayStart - script.Parent.Torso.CFrame.lookVector*Vector3.new(0,3,5)).unit
Ad

Answer this question