Hey,
After long research on the net, i’ve not found a lot of answer to my question … It’s why i’m asking for your help !
I work on a small car game where a car (the player) must survive a amount of time avoiding ennemy cars, who are trying to hit him. More the time you survive, more ennemy are spawning !
Until now I don’t have encounter any trouble (I’ve some knowledge in code)
But my Ennemy AI script is very basic and it’s make the game to easy : It just lookAt the Target et move to him !
But i would like to make something more realistic and more fun :
Something like this !
I’ve found this lesson : Understanding Steering Behaviors: Pursuit and Evade
I’ve undestood the theory but i need some Help for the Script !
Thanks you !
Sorry for my English !
Matthieu
Edit :
I’ve done that :
using UnityEngine;
using System.Collections;
public class Steering2 : MonoBehaviour {
public int Iteration = 30;
public GameObject targetObject;
public Transform target;
public Controller TargetScript;
public Vector3 targetSpeed;
public float rotationSpeed;
public float speed;
// Use this for initialization
void Start () {
targetObject = GameObject.Find ("Car");
target = targetObject.GetComponent<Transform> ();
}
// Update is called once per frame
void Update () {
TargetScript = target.GetComponent<Controller> ();
targetSpeed = TargetScript.InstantVelocity;
Vector3 FuturPosition = target.transform.position + (targetSpeed * Iteration);
Vector3 Direction = FuturPosition - transform.position;
Direction.y = 0;
transform.LookAt (target);
transform.rotation = Quaternion.Euler (270f, transform.rotation.eulerAngles.y, 0f);
//transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Direction), rotationSpeed * Time.deltaTime);
Vector3 moveVector = Direction.normalized * speed * Time.deltaTime;
transform.position += moveVector;
}
}
But i’ve a problem when the target change turn direction, all the police car are going backward !