Making a plane crash detection system

.magnitude isnt an expensive operation. It is just getting a property from a part. I mean what kind of plane crash game. Could you send pics, I might be able to give you a code sample if i know what style it is

1 Like

The game isn’t a plane crash game per se, it’s a game with planes in it that need to be able to crash as part of the challenge of the game.

OOOOH ok good to know ima be afk writing some code for this…

1 Like
while true do
	if (workspace.Baseplate.Position - workspace.Part2.Position).Magnitude > 5 then
		--- 
	end
	wait()
end

I mean we are creating a vector object each iteration (that’s not expensive) what’s expensive is lua making the magnitude property for each vector created, since the distance formula uses square roots. It’s not gonna lag your game or anything though. Also magnitude isn’t a property of a part to my knowledge, It’s a property of vector3.

Also plain mangitude checks don’t really have precice hitboxes. That’s the reason I usually use region3 or raycasting. But most likely magnitude checks are cheaper then these options, not sure though.

How would I use Region3 to detect collisions? I know they can detect objects in their boxes, but if I wanted usable fidelity it seems like I would need to have many of these and that seems like it might not be an ideal solution.

Nothing fancy but here is the model with all the code in it.

https://www.roblox.com/library/5637423556/Plane

yes it works for planes with multiple you dont have to worry!

1 Like

I’m not really sure what your saying, but if your asking wrapping a region3 around every single part that’s defintly bad. What im saying is making a region3 around the whole plane which represents the hitbox using some kinda center point in the plane.

The reason I don’t rely on magnitude checks is they don’t account for size. Even if the plane was touching something far away because it’s size is big it won’t account for collision. Since the distance is still far away.

1 Like

But if I have a Region3 wrapping around the whole plane, won’t that cause collisions to be detected where there are no plane parts?

Yah, and that happens with every method theres no away to get 100% precice collisions without doing a collison around every polygon which is SUPER expensive. With magnitude checks this gap would be even more because it doesn’t account for size. The most precice way would probably be the touched event around a part which is shaped like the plaine.

Touched events aren’t really reliable and they don’t work if your cframing a part to my knowledge.

Raycasting is probably more performant then region3, here is a module which can help you.

Region3 would be more precise tho.

1 Like

Would it be feasible to have say, 5 - 10 Region3 collision detectors? Because one single box wouldn’t be enough for this job but for this particular plane I would estimate that about six would do the job.

Yah it woudln’t be that bad, however if you want a lot of detectors raycasting would be a better option, but raycasting isn’t that good as acting as a precice hitbox.

The best way that I’ve seen for this is to make invisible “collision” parts (set CanCollide to false on them, make them transparent, but listen for .Touched event on all of them). On touched, measure the magnitude of the current velocity (collisionPart.Velocity.Magnitude), and decide how much damage to do.

For example:

collisionPart.Touched:Connect(function(part)
   local mag = collisionPart.Velocity.Magnitude
   if mag > 50 then
      -- Do damage
   end
end)
3 Likes

Would these parts have to avoid intersecting with the plane’s parts for this technique to work?

Probably. Easy to do though. Just check if the part touched is a descendant of the plane model:

collisionPart.Touched:Connect(function(part)
   if part:IsDescendantOf(planeModel) then return end -- Add this
   local mag = collisionPart.Velocity.Magnitude
   if mag > 50 then
      -- Do damage
   end
end)
3 Likes

@ObsidianRook Look at the reply @omgcchheeessee gave above. He sent you a model with code in it - you should probably look at it to see if it’ll work for you.

1 Like

@omgcchheeessee Hey, thanks for this! I tried using it and for some reason it didn’t work - I can’t figure out why, but I appreciate the effort you went to.

@MJTFreeTime Thanks for reminding me - I forgot to reply to tell him I checked it.

To anyone else who may see this, I found a solution - turns out the collision detection from Crazyman32’s biplane free model already implements an improved version of @sleitnick’s suggestion for how to handle the issue and it can be easily ported into just about any plane model - so that’s what I’ve done. Thanks to everyone who responded to this thread for all the help!

2 Likes

I am crazyman32 lol (just changed my username a few days ago). Glad the biplane setup worked for you.

4 Likes

I thought I recognised that hat! Thanks for your help!

1 Like

I noticed that you changed your name when I looked at the smoothcam plugin

Well the code has to be edited. I didnt just make it copy paste.