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.
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);
}
//----------------------------------------------------------------------------------------------------
}
}