Hello and thank you in advance for any help or advice you can share with me.
I am a newbie, but I am going well so far. After the space shooter tutorial I’ve decided to build one of my own that would combine 3D objects in a 2D atmosphere. And fairly I have succeded. The problem is that I stuck with enemy maneuvering script. Unity tutorial had files regarding simple enemy maneuvering (Done_EvasiveManeuver.cs), but Unity’s game has been built in 3D with Z-axis as a main axis. I have translated C# into Java and I am looking at this script and I do not see neither undestand what could be changed to achieve proper maneuvering on X and Y axes. I am suspecting that it might not be entirely because of the axes. Or maybe yes - Unity yells at me that he is “MissingFieldException: UnityEngine.Vector2.z”
What I am trying to achieve is an object coming from the right side of the screen and just change it trajectory.
Coud you at least point me in the right direction. I am trying to tackle this for a week or so, reading related materials and forums, but I may have missed something.
//fire control
var shot : GameObject;
var shotSpawnPoint : Transform;
var fireRate : float;
var delay : float;
var soundRandomizer: AudioClip[];
//Maneuvering
var boundary : Boundary;
var dodge : float;
var smoothing : float;
var startWait : Vector2;
var maneuverTime : Vector2;
var maneuverWait : Vector2;
var currentSpeed : float;
var targetManeuver : float;
function Start () {
InvokeRepeating ("Fire", delay, fireRate);
currentSpeed = rigidbody2D.velocity.x;
StartCoroutine(Evade());
}
function FixedUpdate (){
var newManeuver = Mathf.MoveTowards (rigidbody2D.velocity.x, targetManeuver, smoothing * Time.deltaTime);
rigidbody2D.velocity = new Vector2 (currentSpeed, newManeuver);
rigidbody2D.position = new Vector2
(
Mathf.Clamp(rigidbody2D.position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp(rigidbody2D.position.y, boundary.yMin, boundary.yMax)
);
}
function Evade (){
yield WaitForSeconds (Random.Range (startWait.x, startWait.y));
while (true)
{
targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
yield WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
targetManeuver = 0;
yield WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));
}
}
function Fire () {
Instantiate(shot, shotSpawnPoint.position, shotSpawnPoint.rotation);
audio.clip = soundRandomizer[Random.Range(0,soundRandomizer.length)];
audio.Play();
}