|
hey fokes, can anyone tell me if using this: var LookAtTarget:Transform; function Update () { transform.LookAt(LookAtTarget); } I can make the boat look at me, but the boat directs the front of the boat into me, so my question is, how can i make the boat look at me with his lateral part, where the cannons are, so that after this he can shoot at me.
(comments are locked)
|
|
LookAt aligns transform.forward to the target. If you want to align any other local direction, use FromToRotation:
function Update(){
var dir = LookAtTarget.position - transform.position;
dir.y = 0; // use this to keep the direction strictly horizontal
// rotate left side (-right) in direction to the target:
transform.rotation = Quaternion.FromToRotation(-transform.right, dir);
}
If you want to slowly rotate the enemy ship towards you, use Slerp:
function Update(){
var dir = LookAtTarget.position - transform.position;
dir.y = 0; // use this to keep the direction strictly horizontal
// gradually rotate left side (-right) in direction to the target:
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.FromToRotation(-transform.right, dir), 2.5 * Time.deltaTime); // 2.5 is the speed - adjust it if necessary
}
(comments are locked)
|

Do this:
At some point you will have to make your movement script significantly more complex, but for now this will do.
A little correction: