Hey there!
I’m working on a Universe Sandbox type game, and I want to add collisions, but I don’t know how to add the explosions only where the two parts are touching. I have no idea at all how Ray Casting works, and I haven’t found any great tutorials, so I don’t know what else to do. I appreciate all help you can provide. Thank you!
I’m familiar with touched functions, but I don’t want to know how to make it happen when they collide, I want it to happen where they collide. A regular touched event won’t find that.
I’m not entirely sure, but judging what you would like to do, you would use magnitude.
I believe all you would have to do is find the magnitude of the earth and moon’s position, and use an if statement. You could do this, or you could use raycasts, find the magnitude of ray.Position and earth.Position to give a value, from there you could also use an if statement. My apologies if this was incorrect, if so, best of luck!
From my experience, I learnt it off of a Youtube tutorial. Just make sure you include ‘raycasting properties’, and make sure its a somewhat recent video, as Roblox has changed raycasting.
Keep track of the velocity of one of the bodies. Let’s call this v.
Assuming this body is a sphere, keep track of the radius. Let’s call this r.
On .Touched, do the following:
Raycast from the center of the body with direction v.Unit of magnitude (r+1).
Wherever the ray hits is the point where our body collided with something else.