drag vs mass vs momentum

Hello… I have a problem. When simulating a boat (or any object, really) there is a problem with drag. When some object is submerged, I simply change its drag to a higher value (depending on the size of the object). The problem is, that the drag doesnt take the mass of the object into account… I know, I know… in physics class we all learned that two objects fall at the same speed no matter the mass. But lets imagine two boats - light boat and huge tanker. Both are going at the same speed, and light boat is obviously less submerged - has less drag. If both ships suddenly turn off the engines, I imagine that the tanker would take ages to stop (tankers actually try to reduce the speed hours before reaching the port), but the light boat would stop in an instant. How to simulate this momentum in unity?

The drag for the supertanker and the light boat could be exactly the same, and the supertanker would still take much longer to stop.

Drag is a force that’s proportional to the square of velocity (more or less), and opposite the direction of motion. They both start the same speed, and we’ll imagine they have the same shape (one is, er, an empty supertanker made of styrofoam!), so they have the same drag force.

But F = ma, so a (acceleration) is proportional to F/m, i.e. force divided by mass. Your supertanker has 1000 times as much mass… so it will accelerate (slow down) only 1/1000 as much.

But how do I implement this in Unity? I move the object by AddForce, obviously. When I have two objects (one light, one heavy) and apply the same ammount of force, the lighter one accelerates much faster. But when I make the AddForce 0 and both objects are traveling at the same speed, they both decelerate at the same rate.

That’s not obvious to me. I move objects by changing their transform.position. :wink:

Yes, if you actually need to use PhysX (i.e. Unity’s physics engine), then you are at the mercy of whether they have implemented drag and momentum correctly.

…which it sounds like they haven’t, alas.

Not sure if this will help or not…

You can define physics materials with different friction values. Add them to your gameobjects. AFAIK this is how you tweak the physics engine for different conditions.

I mean that if I have these problems with unity physics, then I obviously use AddForce… I might give the transform.position a try…

Thank you for your reply. But this would require some sort of collider, am I right? I currently dont use any. Only rigidbody

No, that’s not true. More specifically, it’s not true that you have to use Unity’s physics engine (PhysX). For most of my games, even ones where (as in your original post) I am dealing with mass, momentum, and drag, I don’t use the physics engine — I use a few lines of code that implement Newton’s laws myself. I find it easier to make objects do what I want. See this article for an example.

For me, the line where it’s worth it to reach for the physics engine is when I’m dealing with collisions (apart from trivial ones, like a character with the ground). If you want to make an Angry Birds clone, you really need the physics engine, as the math behind all those collision responses gets really complex. If you’re making a flight simulator… well, that’s borderline, because the vehicle model is a little complicated, but you probably don’t have to worry about collisions, so it’s not unreasonable to do it yourself.

It sounds like you’re making some kind of naval simulator, so should you be using the physics engine or not? I dunno, that’s kind of borderline too. If the ships don’t need to collide, then probably not. If they do collide in interesting ways, then yeah, you’re stuck with the physics engine.

Hey, no colliders? That suggests that you don’t need the Rigidbody either. :slight_smile: Consider doing the physics yourself. It really is just:

  • acceleration = sumOfForces / mass;
  • velocity += acceleration * Time.deltaTime;
  • position += velocity * Time.deltaTime;

I mean, there’s a bit more to it (particularly if you have to deal with rotation), but for big, relatively slow things like ships, it’s not all that hard. (Water exerts so much angular drag on a ship that you can pretty much ignore angular velocity, and nobody will notice.)

Sorry I can’t answer that. I’m pretty much a noob, especially in this area. All I know is what I’ve read and the Unity videos. You’ve discovered that applying physics forces to different objects behave the same response. That’s because both objects are using the same default properties the physics engine is using. Applying a physics material to an object changes how the physics engine deals with that object. See https://docs.unity3d.com/Manual/class-PhysicMaterial.html and https://unity3d.com/learn/tutorials/topics/physics/physics-materials for details.

And I think I can answer your question after all. I think you do need a collider to use physics. As @JoeStrout pointed out, if you need to test for collisions, you need a collider. Real solid objects collide with everything that surounds it, solid surfaces like floor or water, but also air and other solid objects. Each has different a different affect as they touch and or collide. A rigidbody is also needed for physics use and work hand in hand with physics materials.

1 Like

Oh, I see what you tried to suggest. Well… This collider physics only applies when two colliders are reacting with each other. For example - buoyancy of my boat is totally unrelated to any sea mesh… There are no colliders involved. The reason is pretty simple - I am generating waves on the sea mesh. If I made a few km² of sea waves with mesh collider, any pc would catch on fire :smile:

Well… Here comes the problem… I would probably need some colliders in the future. Mainly for some projectile hit detection. But I guess those colliders could be totally unrelated to anything else, right?

Right — you don’t need Rigidbody physics just to use colliders for hit detection; you can use things like Collider.Raycast to see whether your projectile’s path intersects a ship.

This is the approach I would recommend. The trickiest thing about a ship simulation is calculating buoyancy, which PhysX won’t do for you anyway. So once you’ve managed that, adding a bit of F=ma is pretty trivial.