So i was watching the Tutos for Space shooter and had manage to make it to what i thought would have been the end of a long road when (surprise surprise) i ran into a bug but i can’t figure out where it is. I’ve followed the steps and had reviewed every and any source to find a solution but yet i am forced to out reach and ask for help. I can’t seem to make the Enemy ship dodge left and right if someone could please help me out that would be amazing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EvasiveManeuver : MonoBehaviour
{
public float dodge;
public float smoothing;
public float tilt;
public Vector2 startWait;
public Vector2 maneuverTime;
public Vector2 maneuverWait;
public Boundary boundary;
private float currentSpeed;
private float targetManeuver;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
currentSpeed = rb.velocity.z;
StartCoroutine(Evade () );
}
IEnumerator Evade()
{
yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
while (true)
{
targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
targetManeuver = 0;
yield return new WaitForSeconds (Random.Range (maneuverWait.x,maneuverWait.y));
}
}
void fixedUpdate ()
{
float newManeuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed);
rb.position = new Vector3
(
Mathf.Clamp ( rb.position.x, boundary.xMin, boundary.xMax ),
0.0f,
Mathf.Clamp ( rb.position.z, boundary.zMin, boundary.zMax )
);
rb.rotation = Quaternion.Euler(0, 0, rb.velocity.x * -tilt);
}
}