Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Space Shooter: Enemy is not dodging

$
0
0
Hello, I have a problem with Space Shooter turtorial. I have no error untill i start the game and enemy needs to dodge. Under the turtorial i can see the script even copy pasted it and still nothing :/. NullReferenceException: Object reference not set to an instance of an object EvasiveManeuver.FixedUpdate () (at Assets/_script/EvasiveManeuver.cs:42) 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 () { currentSpeed = rb.velocity.z; rb = GetComponent (); 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.0f, 0.0f, rb.velocity.x * -tilt); }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>