How do I find the position at which two parts intersect?

So I coded a beam that players can shoot by pressing q. Tho it’s pretty decent as it is already I’d still love it if there was an explosion if the beam came in contact with any terrain or builds.I looked around for events or functions that could help me out with this but I couldn’t find, thus i resorted to creating this post on the forums.Any and all help is appreciated.

That being said here’s a gif of said beam.(Sorry for the low end gif I’m on a really bad laptop and that was the best I could get :grimacing:)

https://gyazo.com/b99d6a39e5f10101988376e8fb496b2e

As stated above the idea here is to have an explosion where the beam and the wall meets.I’m only trying to get the position, I can handle everything else.

Have you tried using FindPartOnRay?
ex: creating a ray with start position being the hand and the end position being where it would end up with no obstructions and then checking if an object is in the path of the ray, and if so then setting where the explosion should happen to the position of where it hit

2 Likes

Have you checked out this article on the Wiki? It covers the basics of ray casting and has a lot of useful code snippets.

EDIT: Is this the code that you’re looking for?

local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

Found on the wiki.

2 Likes

I was afraid I’d need to use raycasting, it always intimidated me for some reason.(I guess it’s because when I think raycasting, i think guns and when i think guns, i think phantom forces and then i just get a load of anxiety :v)

Edit: Jesus was it really that simple?I’ll give it a try

I wouldn’t worry to much about it, once you learn the basics, it is pretty straightforward. Again, I highly recommend the wiki, as it has many great articles and examples for ray casting basics.

1 Like

With a little playing around with the code from your other post I got it to work, thanks! :smiley:

No problem, glad that it helped!