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
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
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.
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.
â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
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: