I am working on a game where you shot an object across the screen. Sometimes it will curve to the left or right depending on some things. It’s a rigged body and therefore I have it’s velocity. I am looking for an elegant way to add some rotation to the object that makes it look even better when the model banks to it’s left or right when in motion. Any ideas?
You could use AddTorque i think it is, even though i have not really played with physics too much at the moment.
Not sure if this method will apply to your game, but when I created a flying game not long ago I went with making the parent r-body as is kinematic and made the model a child that could rotate any way I wanted and just slerp back to position using a modified version of the transform.rotation example from the doc.
I would make a:
public AnimationCuve bankingCurve;
If you then look in your inspector you will notice you can click on this curve and edit it manually. I would then make kind of a sideways S for a curve. So point A would -1,-1, point B would be 0,0 and point C would be 1,1. Then I would adjust the bezier handles to put some ease in and out on so that it is not linear.
I would then get the angular velocity of the Y axis of your object. and use it to evaluate this curve, to then pipe back into the X or Z localEulerAngle of your object.
so
shipTransform.localEulerAngles.x = bankingCurve.evaluate( shipRigidBody.angularVelocity.y / velocityScale ) * bankScale;
velocityScale and bankScale would be float values you would have to play with to get the in and out values into an appropriate range
Setting euler angle values on a rigidbody might cause some issues. So you may have to do something where the visible mesh of the your ship is nested in a parent transform which has the rigidbody. And just the visible mesh of the ship banks to make it appear like it’s banking, but you aren’t actually changing the rotation of the rigidbody. However that may be unnecessary, I don’t know.
All these suggestions are great. Thank you. I will play around with it and see what works best.