Question by
zak666 · Jul 05, 2016 at 08:53 AM ·
quaternionscriptingbasicsslowing-down
Quaternion.slerp changing the rotation speed value dose not Change how fast or slow the ship turns
Hi gang, this seems to be working to a degree, however everywhere i find online they just tell me to just the rotation speed on the sleep to slow or speed up the rotation, however when i change the value to 0.01 or 1000 it doesn't change the speed at all in game to make my ships appear to be flying around until they find a target.
using UnityEngine;
using System.Collections;
public class BattleShipAVA : MonoBehaviour {
private bool Patrolling = true;
private bool Defending = false;
private bool Attacking = false;
private bool DefenceOwned = false;
public static bool IsCalledTodefend = false;
public static float DefendersHP;
public GameObject Target3 = null;
public GameObject Target2 = null;
public GameObject Target = null;
public GameObject DefendingTarget;
public GameObject DockingBayTarget;
//basic stuff
public float Speed = 8f;
public float RotationSpeed = 100f;
public float MoveSpeed = 10f;
public float DampingTarget = 10.0f;
public float DefenceRange = 500f;
public float dist;
private float Newdirectionflighttimer = 100;
public Vector3 randomDirection;
//--------------------------------------------------------------------------------------------------------------------------
// Update is called once per frame
void Update () {
transform.Translate (Vector3.forward * Speed * Time.deltaTime);
//--------------------------------------------------------------------------------------------------------------------------
if (Patrolling == true) {
Defending = false;
Attacking = false;
DefenceOwned = false;
if (Newdirectionflighttimer < 1) {
randomDirection = new Vector3 (Random.value, Random.value, Random.value);
Newdirectionflighttimer = 12;
}
Quaternion rotationA = Quaternion.LookRotation(randomDirection);
transform.rotation = Quaternion.Slerp(this.transform.rotation, rotationA, RotationSpeed *Time.deltaTime);
Newdirectionflighttimer -= 1 * Time.deltaTime;
// always rotate to new direction
Target = null;
if (GameObject.FindWithTag("EarthBroadside") != null)
{
Target = GameObject.FindWithTag("EarthBroadside");
}
if (Target != null) {
//setattacking
dist = Vector3.Distance (Target.transform.position, this.transform.position);
if (dist < 100) {
Attacking = true;
Patrolling = false;
Defending = false;
DefenceOwned = false;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------
if(Attacking == true) {
Patrolling = false;
Defending = false;
DefenceOwned = false;
//dostuff
//follow targeted object.----------------------------------------------------------------------------------------------
Target = null;
if (GameObject.FindWithTag("EarthBroadside") != null)
{
Target = GameObject.FindWithTag("EarthBroadside");
}
if (Target != null)
{
Vector3 relativePos = Target.transform.position - this.transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(this.transform.rotation, rotation, Time.time * RotationSpeed);
}
//------------------------------------------------------------------------------------------------------------------------------
// if target is destroyed search for a new target.--------------------------------------------------------------------------
if(Target = null){
Patrolling = true;
Defending = false;
DefenceOwned = false;
Attacking = true;
}
//--------------------------------------------------------------------------------------------------------------------------
} // END ATTACKING
//--------------------------------------------------------------------------------------------------------------------------
if (Defending == true) {
Patrolling = false;
Attacking = false;
DefenceOwned = false;
// fly to defender Unit if called be another unit and this unit is not already defending.
if (IsCalledTodefend == true && DefenceOwned == false) {
Target3 = null;
if (GameObject.FindWithTag ("Defend") != null) {
Target = GameObject.FindWithTag ("Defend");
}
if (Target3 != null) {
DefenceOwned = true; // is owned cannnot be called be another ship
DefendersHP = Target3.GetComponent<ShipMananger>().HP;
Vector3 relativePos = Target3.transform.position - this.transform.position;
Quaternion rotation = Quaternion.LookRotation (relativePos);
transform.rotation = Quaternion.Lerp (this.transform.rotation, rotation, Time.time * RotationSpeed);
dist = Vector3.Distance (Target3.transform.position, this.transform.position);
}
if (dist < 100 && DefendersHP < 3000) {
//defend this target untill hp recorverd
//follow targeted object.----------------------------------------------------------------------------------------------
Target = null;
if (GameObject.FindWithTag ("EarthBroadside") != null) {
Target = GameObject.FindWithTag ("EarthBroadside");
}
if (Target != null) {
Vector3 relativePos = Target.transform.position - this.transform.position;
Quaternion rotation = Quaternion.LookRotation (relativePos);
transform.rotation = Quaternion.Lerp (this.transform.rotation, rotation, Time.time * RotationSpeed);
}
//------------------------------------------------------------------------------------------------------------------------------
}
}
}
}
//------------------------------------------------------------------------------------------------------------------------
void OnCollisionEnter(Collision other) {
if (other.gameObject.CompareTag ("boundry")) {
randomDirection = new Vector3 (Random.value, Random.value, Random.value);
}
}
//------------------------------------------------------------------------------------------------------------------------
}
Comment