aim the enemy to me, Rotate(90 * Vector3.up)

Hello, i have this script that i’ve seen from a question here on unity answers, and i’m trying to adapt it to me, but a cant, i’m making a battleship game, and i need the enemy to target me, so he needs to be pointing at me, but since i’ve use someone else script, now i cant put Rotate(90 * Vector3.up), so that he looks lateral at me, can some one help?
this is my script:

# pragma strict

var speed = 3000;

var distance : int;
var maxDistance = 50;
var myTransform = transform;
var LookAtTarget : Transform;
var bullitPrefab : Transform;
var damp = 6.0;
var savedTime = 0;

function Update () 
{
    distance = (LookAtTarget.position - myTransform.position).magnitude;
    
    if(LookAtTarget && distance < maxDistance)
    {
        var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); //this is what i want: transform.Rotate(90 * Vector3.up);
    
        transform.rotation = Quaternion.Slerp(transform.rotation,rotate,Time.deltaTime * damp);
        var seconds : int = Time.time;
        var evenodd = (seconds / 2);
        if (evenodd) 
        {
            Shoot(seconds);
        }
    }
}  
 
function Shoot(seconds)
{
    if(seconds != savedTime)
    {
        var bullit = Instantiate(bullitPrefab,transform.Find("spawnPoint").transform.position,
                    Quaternion.identity);
        bullit.rigidbody.AddForce(-transform.right * speed);
        savedTime = (seconds);    
    } 
}

There is a few ways to do what you want:

  1. you can multiply your rotation quaternion by another quat with needed rotation (there is function to construct quat by axis and angle, then you need to multiply var rotate by it - note what multiplication order is important). you need to know some math to do it right, or just make some experiments.

  2. you can create dummy(empty) GameObject and link your model to it. (make children, i.e. drag your model at dummy in scene tree view). then you need to setup relative rotation in editor. this is the common way - any object can be adjusted, just make parent dummy object for it. also you can adjust center of rotation using this trick.

var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position + Vector3.up*90)

Depending on which direction you want it to rotate you might minus it, or change it to one of the other vectors (right, forward…)

because we’re dealing with vector3’s and rotation here… silly me.

If you just want to rotate the target rotation by 90°, just do something like that:

var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
var r90 = Quaternion.Euler(0,90,0);
rotate *= r90;

transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

You might need to use -90 but in general that should work.

ps: the whole evenodd thing doesn’t work. You don’t compute the modulo, you just divide the seconds. The if will be true as long as seconds is 2 or greater, which it is after two seconds…

Also there are a lot unnecessary calculations. Also you have a chached transform (myTransform) but you still use transform. Also distance and maxDistance are integer which doesn’t make much sense. It also looks like you don’t use the distance variable somewhere else in your script, so it should be just a local variable and not a member variable.

function Update () 
{
    var targetDirection = (LookAtTarget.position - myTransform.position);
    var distance = targetDirection.magnitude;
    
    if(LookAtTarget && distance < maxDistance)
    {
        var rotate = Quaternion.LookRotation(targetDirection ); 
        var r90 = Quaternion.Euler(0,90,0);
        rotate *= r90;
        
        myTransform.rotation = Quaternion.Slerp(myTransform.rotation, rotate, Time.deltaTime * damp); 
        var seconds : int = Time.time;
        var evenodd = (seconds % 2);  // modulo operator
        if (evenodd) 
        {
            Shoot(seconds);
        }
    }
}