Hello, I`m already tried for 4~5 hours to make that script to work.
The problem is ;
When the magintude of the transform.position reaches below 1 from the first waypoint, it has to rotate, but it doesnt rotate…
I tried LookAt I tried Quaternion.LookRotation,
but nothing works. but then I tried Destroy(gameObject); , and it did destroy it.
I try to rotate the gameObject in lines 61-64
Is there any other rotation? Like making the rotation automatically in run-time another rotation? without LookAt, something like :
transform.rotation(x,y,z);?
the code in website:
http://www.pasteit4me.com/90005
using UnityEngine;
using System.Collections;
public class AIIscript : MonoBehaviour {
//game objects (variables which point to game objects)
Vector3[] waypoints = new Vector3[13];
private GameObject objCamera;
private VariableScript ptrScriptVariable;
int current = 0;
//input variables (variables used to process and handle input)
private Vector3 inputRotation;
private Vector3 inputMovement;
private bool meleeAttackState;
public GameObject objWP1;
//identity variables (variables specific to the game object)
public float moveSpeed = 8000f;
public float health = 50f;
// private bool thisIsPlayer;
// calculation variables (variables used for calculation)
private Vector3 tempVector;
private Vector3 tempVector2;
// animation variables (variables used for processing aniamtion)
// Use this for initialization
void Start () {
Debug.Log("Start for " + this.GetType() + ": " + Time.time);
if (gameObject.tag == "Player")
{
// thisIsPlayer = true;
}
waypoints[0] = new Vector3(97,0,97);
waypoints[1] = new Vector3(101,0,52);
waypoints[2] = new Vector3(275,0,52);
}
// Update is called once per frame
void Update () {
inputMovement = waypoints[current] - transform.position;
if (health <= 0)
{
Destroy(gameObject);
}
ProcessMovement();
}
void ProcessMovement()
{
if ((transform.position - waypoints[current]).magnitude < 1)
{
++current;
}
// The problem in that "if" it doesn't effect on the dog.
// if I add Destroy(gameObject); , then it affects.
if ((transform.position - waypoints[0]).magnitude < 1 (transform.position - waypoints[2]).magnitude < 1)
{
transform.rotation = Quaternion.LookRotation(waypoints[1]);
}
tempVector = rigidbody.GetPointVelocity(transform.position) * Time.deltaTime * 1000;
rigidbody.AddForce (-tempVector.x, -tempVector.y, -tempVector.z);
rigidbody.AddForce (inputMovement.normalized * moveSpeed * Time.deltaTime);
transform.rotation = Quaternion.LookRotation(inputRotation);
//It works, It's upwards.
transform.eulerAngles = new Vector3(180,transform.eulerAngles.y + 180,0);
transform.position = new Vector3(transform.position.x,0,transform.position.z);
}
}