Question by
MonsiuorMorbid · Feb 13, 2018 at 12:54 AM ·
codepage
Evasive Maneuver causing Space shooter enemies to not move?
I'm adding enemies to the Space Shooter when the Coding for Evasive Maneuver keeps preventing the Enemy ships moving down the screen. The code for Evasive Maneuver:
using UnityEngine; using System.Collections;
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.0f, 0.0f, rb.velocity.x * -tilt);
}
}
and the Code for Mover: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Mover : MonoBehaviour {
public float speed = 1.0f;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody> ();
rb.velocity = transform.forward * speed;
}
}
and the code for Weapon controller
using UnityEngine; using System.Collections;
public class WeaponController : MonoBehaviour {
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
public float delay;
private AudioSource audioSource;
void Start ()
{
audioSource = GetComponent<AudioSource> ();
InvokeRepeating ("Fire", delay, fireRate);
}
void Fire ()
{
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
audioSource.Play ();
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity coding problem 1 Answer
Error message with script 2 Answers
c# cods spaceship 0 Answers
my script has been breaking 0 Answers