So now I’m making a molotov, but I need some way to detect if it is grounded before it explodes, so that it doesn’t explode when it hits a wall or something like that. Using :IsGrounded() on BaseParts doesn’t really work that well because the part has to be orientated a certain way to the ground for it to be passed as true. So, how can I do this?
I’ve thought of raycasting, but it could still theoretically explode on a part that isn’t at ground level if the raycast hits it. My only idea right now is to raycast and compare the hit parts’ positions Y position to a global ground vector (0, 0, 0) and then use magnitude to determine how far up it is and only explode it when the magnitude is below a certain number, but I’m not sure how effective this is. Any ideas?
Edit: Actually, my method wouldn’t work because I also want them to explode if let’s say it hit the top of a building. The position of the hit part would be too far from the ground vector
Actually I think I’ll raycast radially from the molotov’s position, and then detect if I get a hit from all of the raycasts to determine if the part is fully grounded. I think it’ll work
Yeah but then I’d have to whitelist every single edge case like that for my game. The map for the main game is huge and there’s probably a more efficient way to do it
Why wouldn’t you want the molotov to explode when it hits a wall or ledge?
That would be realistic.
If you want it to only explode on certain parts why not name those parts “Explode” or something similar, then have the OnTouch signal fire only if the name of the Part it hits is Explode. That way it’ll bounce off all the other Parts and only go boom when it hits one of those ‘ground’ Parts.
It looks like an attempt at a CS:GO-style Molotov, because in the game if a molotov hits a wall it doesn’t break and spread fire, only when it hits the ground.
Although I do agree that it would be realistic if OP just let it explode nonetheless
Yeah. The reason why I’d want it to only explode when it hits the ground is so that the fire spreads correctly and actually has enough space to spread to look right. If it exploded on a wall or a small ledge, the fire would be floating. Also letting people bounce molotovs off of walls would lead to some interesting gameplay
You can check if the surface normal of the ray cast, the top surface is 0, 1, 0 so if the surface normal is that then you have hit the top of something.
At first this sounded like a really good idea, but when you’re building, especially a large map, a lot of parts are orientated differently depending on how the builder rotates it. So the wall to a building you see could actually be the part’s top surface, for all you know. So I’m not sure if this idea is really the safest.
I think I’m going to stick with my solution of radial raycasting downwards from the molotov’s position and wait until all of them are detecting hits to detect if the part is on the ground, it seems like the most efficient and safest solution right now. I’ma test it out later