Is it possible to have air drag?

Can anyone tell me how to create air drag? I understand the drag for a standard rigid body on a mesh, but how do you create drag if the character controller is flying?

RigidBody.drag/angularDrag is air drag, effectively, since it works whether or not the object is touching something.

If it’s not exactly what you want, you can always apply a force in the opposite direction to the one which you’re travelling in, and scale the force in relation to the velocity using some function of your own devising.

that’s what I figured, but increasing the drag doesn’t seem to have any effect on slowing the velocity once I accelerate. I have tried increasing the number up to 5 with no visible effect.

Am I missing something (probably)? How does it work, then?

If you’re directly translating an object with scripting (which you are), then you’re not going to see any effects of drag. That only affects objects that are being moved by the physics engine.

I think in general you either want to have movement 100% through the physics engine or 100% through direct translations; trying to mix the two won’t work very well. If you apply relative forces to a rigidbody and let the physics engine take care of everything, that makes some things easier, but can be hard to tune properly. On the other hand, directly translating everything gives you complete control, but can result in a lot of scripting if you have complex movement.

–Eric

1 Like

So, how would you move an object through space with the physics engine? Would you apply a pushing force behind to move forward, stuff like that?

How can you translate an object’s position and rotation without direct translation? Maybe that’s a dumb question, but I’m really still getting a handle on the basis of programming.

The most useful function for this is:

// Moves the object forward
rigidbody.AddRelativeForce(Vector3(0, 0, 10));

The most important part is, don’t directly modify the position, don’t directly modify the velocity. Just add forces.

A good example of how to make rigidbody based flying vessels is aarku’s ship control script used in overwhelmed arena:

Yes. You’d use AddForce or AddRelativeForce to make something move around and AddTorque or AddRelativeTorque to make it rotate. For clarity, torque can be thought of as a vector which points along the axis of rotation, whose length is the ‘strength’ of the change in rotation.

You can read about these methods in the Rigidbody documentation.

Hi, Mr. Carter :wink:

Got it. I will look over the docs again although I think I have a handle on the principles (the Unity guys made the process as common sense as possible).

Now here is the question:

Given the current script I am working with, do I

1 ask the programmer to start again using the method we are discussing for the longterm ease of use (ie, will that piss him off)?

2 try to amend the current script to allow the physics engine to handle the mechanics the way we are discussing?

Which is better long term?

It’s difficult to say whether it’s really necessary or preferable to program the affected scripts from scratch without knowing what the code looks like. However, I’d imagine that the changes which need to be made to use forces aren’t too severe. It’s likely that quite a lot of code will need to be altered in relatively simple ways.

Whether or not that annoys your programmer is another matter. :wink:

Assuming we’re talking about the FlyControl script, I’d politely suggest starting over, and have your programmer look up Input.GetAxis and use that instead of GetKeyDown. If that pisses him off, get another programmer. :wink:

–Eric

Yes, we are talking about the FlyControl script, and he’s a volunteer so I’d hate to lose him. He wrote that script from his first few days with Unity, so maybe I can convince him to clean it up. Maybe :wink:

Thanks.

Programmers respond well if you pat them on the head and say “good boy!” Or am I revealing too much here? :?

–Eric

Everyone responds well to 'Good boy" except women. No real shock there, but thanks for the insight.

Good boy! :lol: