Rotate my battleship 90 degrees Once In Range?

Hey Gang, Just winding how I can turn smoothly my GameObject 90 degrees so my battleship Will give my enemies a good broadside.
the enemy finds and flies at a target and once in rang, i want the ship to turn so the side of my battleship is facing the enemy. :slight_smile:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class BattleShipAi : Photon.MonoBehaviour {
    
    	public GameObject Target;
    	public GameObject[] Targets;
    
    	public bool OurTeam;
    	public bool Selected;
    	public bool Attacking;
    	public bool BroadSide;
    
    	public 	float distance = 2000;
    	public int index;
    	public float RotationSpeed =  0.4f;
    
    	private Quaternion _lookRotation;
    	private Vector3 _direction;
    
    	public EngineAi Engine;
    	public PlayerAntiLock AntiLock;
    
    	void LateUpdate ()
    	{
    		if (PhotonNetwork.isMasterClient == true) {
    
    			//----------------------------------------------------------------------------------------------------
    
    			if(BroadSide == true){
    				Debug.Log ("BroadSide");
    				// Give em hell'
    				// turn 90 to side on the enemy ship.
    			}
    				
    			//----------------------------------------------------------------------------------------------------
    
    			if (Target != null) {
    				Selected = true;
    				distance = Vector3.Distance (Target.transform.position, transform.position);
    
    				if (distance < 100) {
    					BroadSide = true;
    					Engine.enabled = false;
    				}
    
    				if (distance > 100) {		
    					BroadSide = false;
    					Engine.enabled = true;
    				}
    			}
    
    			//----------------------------------------------------------------------------------------------------
    
    
    			if (Target == null && Attacking == true && OurTeam == true) {
    				Selected = false;
    				Targets = GameObject.FindGameObjectsWithTag("TeamTwoHeavy");
    				index = Random.Range (0, Targets.Length);
    				Target = Targets[index];
    				if (AntiLock == null) {
    					AntiLock = Target.GetComponent<PlayerAntiLock> ();
    					if(AntiLock.AntiLock == true){
    						Target = null;
    						AntiLock = null;
    					}
    				}
    
    				}
    
    			}
    
    		if (Target == null) {
    			AntiLock = null;
    		}
    
    
    			if (Target == null && Attacking == true && OurTeam == false) {
    				Selected = false;
    				Targets = GameObject.FindGameObjectsWithTag("TeamOneHeavy");
    				index = Random.Range (0, Targets.Length);
    				Target = Targets[index];
    			if (AntiLock == null) {
    				AntiLock = Target.GetComponent<PlayerAntiLock> ();
    				if(AntiLock.AntiLock == true){
    					Target = null;
    					AntiLock = null;
    				}
    			}
    
    			}
    
    			//----------------------------------------------------------------------------------------------------
    
    			if (Target == null && Attacking == false) {
    				Selected = false;
    				Targets = GameObject.FindGameObjectsWithTag("Waypoint");
    				index = Random.Range (0, Targets.Length);
    				Target = Targets[index];
    
    			}
    
    			//----------------------------------------------------------------------------------------------------
    
    
    			if (Target != null && BroadSide == false) {
    				_direction = (Target.transform.position - transform.position).normalized;
    				//create the rotation we need to be in to look at the target
    				_lookRotation = Quaternion.LookRotation(_direction);
    				//rotate us over time according to speed until we are in the required rotation
    				transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
    			}
    
    			//----------------------------------------------------------------------------------------------------
    
    
    
    		}
    
    	}

You already seem to have code for looking at the target so use same code, but offset rotation on Y-axis by 90 degrees. I didn’t test this, but I think it should more or less do what you want.

_direction = (Target.transform.position - transform.position).normalized;
_lookRotation = Quaternion.LookRotation(_direction);
_lookRotation = Quaternion.Euler(new Vector3(_lookRotation.eulerAngles.x, _lookRotation.eulerAngles.y + 90f, _lookRotation.eulerAngles.z));
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);

You have your look rotation, multiply it by Euler 0, 90, 0 and you achieve left broadside look direction and -90 will make it right broadside, simplest and best working solution.

Hello,
Call this function you would battleship Turn to enemy
public var enemy : Transform;
function SOMETHING (){
transform.LookAt (enemy);
}