[HELP] How to move ray origin position forward depending of lookVector

Last time I tried to do something similar, it didn’t work well, no… I don’t remember the reason, but it didn’t work with me, I’ll try it out again.

Remember to only compare the normal’s Y value. If it’s above 0, not equal or less than, then it’s a floor.

1 Like

so it would be this?

if upVectorY >= 0 then 
-- logic
end 
if upVectorY > 0 then 
-- logic
end 

If the normal’s Y value is 0 or less, the raycast hit a wall or ceiling.

1 Like

Got ya! let me try this out… It seems so simple, last time I did it with normals, I was doing bunch of crap :joy:

1 Like

Now I remember why this method didn’t work… what happens if you’re on top of a hill? the Y axis would be higher right?

Edit: Imagine a part → The top would be a floor, the sides would be considered walls.

Last time I used normals to detect if they were walls, they gave me this:
eyJhbGciOiJIUzI1NiJ9.eyJpbWciOiJfOWU5MTYwOTdlNDFhYjVjYjc0NGU0NmQyNGEyMmIyZGQifQ.uy0tpDxA_1gAejdAmVV96G_oypffUkQQ5hOUp2ot-Qk-png

a 1 would be equal to a wall… the Y would be equal a decimal if a ramp, and a 0 would be a floor… but it was tough for me to do the logic after that.

When the Y value is 1, it’s a flat floor. Anything above 0 and not equal to 1 is some sort of slope.

1 Like

Ohhhhh, now I see where you’re going with this…

Should the ray’s origin still be the camera? cause due to the weird inverse ray it’s ruining the script.

Using the camera as a raycasting origin for something like this is a bit weird.

1 Like

True indeed… but where else should it be? the character’s Y pos? If I do that, the projectiles won’t be able to place down surfaces underneath or above the character, will it?

Technically I’m using the mouse- but yeah it’s also the camera :sweat_smile: :joy:

Well I would raycast from the projectile’s position to the point of collision

1 Like

What do I mean by that? this:

Mmm… ok ok, so- how do I direct the ray to the point of collision? with direction I assume?

Use the projectile’s LookVector to detect collision.
I use projectile as a placeholder variable here, I don’t know how you reference it in your script

local origin = projectile.Position;
local direction = projectile.CFrame.LookVector * 5;

Also you can change 5 to however many studs you want to raycast forward.

1 Like

You made my life so much easier I wanna cry… You don’t know how many different methods I’ve tried… and the most simplest and logical one made by you worked :sneezing_face: :sob:

This is my 5th day scripting, so yeah I’m not that experienced, thank you so much though!!! I owe you everything. Thank you so much for your time, dedication, and patience :joy:

1 Like