- Home /
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!
Answer by keimax1981 · Apr 03, 2013 at 01:17 PM
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);
}
I've voted this up because I've been stuck on a similar problem for a couple of days and this has been a workaround for me ..
Your answer
Follow this Question
Related Questions
Is there a better way to tilt terrain at runtime? 1 Answer
Autorotation to tween gameobject 0 Answers
How can i follow an object by 1-axis-rotation? 0 Answers
Preventing "LookAt" from flipping? 1 Answer
Another way to follow an object? 2 Answers