rotate and tilt at the same time

Hi,

my spaceship is using lookat to face the target vector. (RTS style game, topdown view)
I would like to tilt (lean) the spaceship to the left or to the right when depending on the angle between ship and tartget.
I tried modifying one axis while rotating, but thats not working since transform.lookat
will not allow to change the rotation.

Thanks for your help!

1 Like

Thanks but that did not help. Baking and look rotation on one game object at the same time causes many problems.
I got it working now.

I have now 2 game objects.

Parent: Deals with the lookrotaion of the object.

Child: is used for banking the object.

Code used:

var target : GameObject; // where to fly and look to.
    var turnSpeed = 130f;
    var maxBank = 130f;
    var moveSpeed = 2f;
    var banker : GameObject; // Child of this transform
  
   
    
       function Update ()
    {
    var currentTarget =target;
 
    var lookDirection = currentTarget.transform.position - transform.position;
    var normalizedLookDirection = lookDirection.normalized;
    var bank = maxBank * -Vector3.Dot(transform.right, normalizedLookDirection);
    var rot = Quaternion.LookRotation(normalizedLookDirection);
    banker.transform.localRotation = Quaternion.AngleAxis(bank, Vector3.forward);
  
    transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime * turnSpeed/300 );
    transform.Translate(new Vector3(0,0,moveSpeed) * Time.deltaTime);
    }