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!
Here’s an example of what I’m trying to achieve:
I’m not sure what exactly you’re asking? Do you mean when the two planets touch each other, you start an explosion?
Yes, and I want the explosion to only happen where they touch. I’m not sure how to do this.
A Touched event,
if hit.Parent.Name = "Moon" then
local explosion = Instance.new("Explosion")
-- blah blah blah
Yeah, but that wouldn’t really work too well, since I want the explosion to start only where the planets collide with each other.
yeah it will only start when the planets collide because,
touched is a function that starts when something is being touched
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.
OH. I’m sorry I didn’t see the where part.
yeah I’m sorry I don’t know either. try reading a few posts on the devforum
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!
Thanks! I am not very familiar with raycasting, as I stated in my OP, but do you have any ideas or suggestions to help me learn it?
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
Assuming this body is a sphere, keep track of the radius. Let’s call this
On .Touched, do the following:
Raycast from the center of the body with direction
v.Unit of magnitude
Wherever the ray hits is the point where our body collided with something else.
You can also refer to a developer hub post and see if you can figure out how to incorporate it into your project: