Rotate a Spaceship

Hello everybody :slight_smile:

I’m doing a Strategy game with spaceship , and I have some difficulty to find how to achieve the rotate of my spaceship.
I don’t use keyboard to move in specific direction, I select a target to get destination position.

For now to move my spaceship, i’m using a simple code :

    void FixedUpdate()
    {
        if (target != null)
        {
            if(Vector3.Distance(transform.position, target.position) < 5)
            {
                rb.velocity = Vector3.zero;
                return;
            }

            rb.velocity = transform.forward * speed * Time.fixedDeltaTime;
            var targetrotation = Quaternion.LookRotation(target.position - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetrotation, turnSpeed  * Time.deltaTime);
        }
    }

but would like to add the effect of movie’s spaceship. When my ship go to a destination, I would like to it to rotate on his Z axis and his Y axis.

For the example I post a image to explain :

So I would like to know if there is a way to achieve that ?
If someone can help me i’ll really appreciate because it’s seems to be sorcery for me and my programming level ^^’

Have a nice day :slight_smile:

You probably want to handle the Y and Z axes differently.

Y should be configured to slowly change around to the heading the plane should go in.

Z could be configured to bank when Y is changing, and not bank when going straight.

You could parent things to do this easily:

RotationAroundYAxis (Heading)
BankingAroundZAxis (Tilting)
TheActualVisibleGraphicPortion```

Then you drive one axis of the .localRotation of the two middle transforms.

You can see an example here:

Turret aiming/rotating:

https://discussions.unity.com/t/783469/2
1 Like