Problem with raycast not going further than direction

Hello, I’m doing a raycasting and I’m getting raycast direction by doing destination - origin . It works fine but as said in the raycast page


which is a problem since I want it to go further. There may be a very simple way to achieve this but I’m bad at math and math in 3D space is worse. I need to change my destination so it’s further from where it is now but without it changing the raycast general direction. I’m getting the destination with a part position and it’s from a random part so I can’t just input a hard value like -100 on the y. (Maybe I have another problem in my code but I’m pretty sure it’s coming from this).
Thanks for reading !

1 Like

Could you show us some code so we can see the problem a bit better

1 Like

You can get the Unit of the direction vector and multiply by how many studs you want to go:

local Origin = Vector3.new(0,0,0)
local Direction = (Vector3.new(6,8,10) - Origin).Unit --Returns direction Vector3 with magnitude of 1.
workspace:Raycast(Origin, Direction*100) --Ray will travel until it hits something or goes on for 100 studs, you can put a negative value to make the ray go other way.

Thanks, I was sure there was a “easy” way. Didn’t knew I could do it like that but that’s exactly what I was looking for !

It’s okay @ BenMactavsin gave what I wanted ( sorry if my post wasn’t clear enough but it was pretty specific)

1 Like