So I have a rogue squadron style spaceship controller which is working good and well. Every fixed update it runs the following:
Roll = -InputAxis.x * rollRate * dT;
protected virtual void ApplyForces()
{
rb.AddRelativeTorque(new Vector3(Pitch, Yaw, Roll), ForceMode.VelocityChange);
rb.AddRelativeForce(new Vector3(Strafe, Lift, Thrust), ForceMode.VelocityChange);
}
Now my issue is, if I set the roll to be anything but a number close to 0, if the ship rolls too much my roll will be too severer.
Say I’m moving the joystick left → the ship rotates, now moving left is moving the ship down in space.
So the simple solution is to simply set roll to 0.
Now what I want to do is to add some visual flair. Instead of actually rolling the ship, I put the colliders and visuals of the ship in a child gameobject with the transform bankTransform
and to make it look like the ship is tilting in every update I run:
bankTransform.localRotation = Quaternion.Euler(0f, 0f, maxBankDegrees * -InputAxis.x);
This code works and has the effect I desire (visual tilting the ship in response to controller inputs; without actually rolling the ship and altering the axis of control.
The problem is that I am manually altering the rotation of colliders that are attached to a rigidbody. I believe this has a significant performance cost right (since I’m not using rb.AddRelativeTorque)?
I can’t seem to think of a good way to do this visual tilt using rb.AddRelativeTorque() as I want to tilt the ship without altering the axis of movement of the ship. Anybody got some clever ideas?