Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AlexPoe · Mar 04, 2015 at 05:47 PM · scriptingproblem

Space Shooter Enemy AI Maneuver Script

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();
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Mar 04, 2015 at 11:11 AM 0
Share

Perhaps deal with your error first.

avatar image AlexPoe · Mar 04, 2015 at 05:43 PM 0
Share

What error? "$$anonymous$$issingFieldException: UnityEngine.Vector2.z"? I tried to find explanation for this, but no sound explanation for me. If you could help me understand where to start analysing it, I could do it myself!

Thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UDM1983 · Dec 29, 2018 at 08:48 AM

Vector2 has only two components, and x and a y. The moment you add the third component, we are talking about Vector3. So instead of Vector2, in 3D you need to use Vector3. Also, in 3D, you should use Rigidbody and not Rigidbody2D... all colliders need to be for 3D (even if your game is basically 2Dish). Hope this helps and good luck.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

unity 3.4 crashes when i get to a certain point in the character generator script? 0 Answers

How to create a UnityScript array and access the data in each cell. 1 Answer

Help me to fix my script error cs1519 1 Answer

How to delete animation event from .fbx file using script 0 Answers

Swapping animation clips at runtime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges