Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by woutervangerven · Dec 21, 2016 at 07:30 AM · argumentoutofrangeexception

Argument out of range Exception & Waypoint problem

Hey guys,

I got an problem the problem sounds like this... I have a system that sets up waypoint for an airplane to travel to. The first problem is that the waypoints aren't set and the second problem is that it gives an argument out of range error if I try to start it. I have an boolean thats called started that I have to enable to let it start.

(The Argument out of range problem could be because I can't set waypoints, and i'm dutch so don't mind my english xD)

Update: (The fault if in line 89. Thats the line that begins with: Vector 2 dir = ....)

Here is my code: using UnityEngine; using System.Collections; using System.Collections.Generic;

 public class Waypoint : MonoBehaviour {
 
     List<GameObject> waypoints = new List<GameObject>();
 
     public GameObject waypoint;
 
     public float time = 0;
     public int current = 0;
     public int PreCurrent = 0;
     Vector3 startpos;
     Vector3 endpos;
     Quaternion startrot;
     [Range(1,10)]
     public float speed = 1;
     [Range(1, 10)]
     public float rotspeed = 1;
     public int lastplaced = -1;
 
     public bool started = false;
     public bool rotating = true;
 
     void Start () {
         startpos = transform.position;
         startrot = transform.rotation;
         
     }
     
     void Update () {
 
         if (Input.GetMouseButtonDown(0))
         {
             Vector3 s = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             s.z = 0;
             s.x = Mathf.Round(s.x);
             s.y = Mathf.Round(s.y);
 
             bool straight = false;
 
             Vector2 go;
 
             if (lastplaced == -1)
             {
                 go = transform.position;
             }
             else
             {
                 go = waypoints[lastplaced].transform.position;
             }
 
             if ((int)go.x == (int)s.x || (int)go.y == (int)s.y)
             {
                 straight = true;
             }
 
             if (straight)
             {
                 //waypoints.Add((GameObject)GameObject.Instantiate(waypoint, s, new Quaternion()));
                 //lastplaced++;
             }
             else
             {
                 Debug.LogError("You cannot go sideways!");
             }
         }
         if(started && !rotating)
         {
             transform.position = Vector3.Lerp(startpos, waypoints[current].transform.position, (time * speed / Vector2.Distance(startpos,waypoints[current].transform.position)));
             endpos = Vector3.Lerp(endpos, waypoints[current].transform.position, (time * speed / Vector2.Distance(endpos, waypoints[current].transform.position)));
             if(time * speed / Vector2.Distance(startpos,waypoints[current].transform.position) >= 1)
             {
                 current++;
                 if (waypoints.Count == current)
                 {
                     started = false;
                 }
                 time = 0;
                 startpos = transform.position;
                 startrot = transform.rotation;
                 rotating = true;
             }
             time += 0.01f;
         }
         else if (rotating && started)
         {
             Vector2 dir = waypoints[current].transform.position - transform.position;
             float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
             Quaternion rot = Quaternion.AngleAxis(angle, Vector3.forward);
             transform.rotation = Quaternion.Lerp(startrot, rot, time * rotspeed);
             if (time * rotspeed >= 1)
             {
                 rotating = false;
                 time = 0;
             }
             else if(rot == startrot)
             {
                 time = 0;
                 rotating = false;
             }
             time += 0.01f;
         }
     }
 }
 
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

Argument out of Range 1 Answer

ArgumentOutOfRangeException: Argument is out of range in Generic.List 2 Answers

Delegate value does not fall within the expected range 1 Answer

For loop not repeating - (JAVASCRIPT) 1 Answer

List Emptying Itself? 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