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

How to make raycast face lookVector?

Asked by 1 year ago

No matter in which way i shape the code i havent been able to get the raycast to be perfectly oriented towards the lookvector.

The script outputs that the raycast is not hitting anything, which should not be possible considering the origin of the raycast is located within 6 walls, therefore the sky is not visible at all.

picture of where the raypart is located: (imgur.com/a/h7j1kZh)

Heres the code:

while true do
    local result = workspace:Raycast(script.Parent.startP.Position, script.Parent.startP.CFrame.LookVector)
    if result then
    local newpart = Instance.new("Part", workspace)
    newpart.Position = result.Position
    newpart.Shape = Enum.PartType.Ball
    newpart.Size = Vector3.new(0.1,0.1,0.1)
    newpart.BrickColor = BrickColor.Red()
    newpart.CanCollide = false
    newpart.CanQuery = false
    newpart.CanTouch = false
    newpart.Material = Enum.Material.Neon
    wait()
    newpart:Destroy()   
    else
        wait()
        warn("No raycast result!")
    end
end

Thanks to anyone that helps in advance

1 answer

Log in to vote
0
Answered by 1 year ago

You've given the RayCast a direction, but haven't given the direction a length.

As an example, adding * 5 to the direction will make it RayCast 5 studs in that direction.

script.Parent.startP.CFrame.LookVector * 5
0
oh, i never understood what that * x meant at the end of it, ill check it out tomorrow and see if it works. also, just to tell you i sometimes with some solutions have an issue where the lookvector isnt exactly the face, sometimes its offset to the side and its rotation only matches up every 90 degrees so ill see if this solution works. BloxyCola_Gamer 10 — 1y
0
works perfectly and no offset, i cant thank you enough! BloxyCola_Gamer 10 — 1y
Ad

Answer this question