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
0
Question by zmar0519 · May 05, 2011 at 10:05 AM · aiwaypoint

waypoint ai script not going all the way to waypoint

hello, everyone. I have this waypoint ai script, but it doesn't go all the way to the waypoints, it stops short I have no idea how to fix this. all help would be appreciated.

Here is my code:

@script RequireComponent(Rigidbody) enum mt { Sequence, Patrol } var waypoint : Transform[]; var speed : float = 20; var movementType : mt; private var currentWaypoint : int; function Awake() { if(movementType == mt.Patrol) transform.position = waypoint[0].position; } function Update() { if(currentWaypoint < waypoint.length) { var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position;

     var velocity = rigidbody.velocity;
     if(moveDirection.magnitude &lt; 1){
         currentWaypoint++;
     } else {
         velocity = moveDirection.normalized * speed;
     }

 } else {
     if(movementType == mt.Patrol)
         currentWaypoint = 0;
 }

 rigidbody.velocity = velocity;

}

Comment
Add comment · Show 1
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 Cyb3rManiak · May 05, 2011 at 11:07 AM 0
Share

How close to the waypoint does it go? From a brief scan of your code, I would say that it either stops 1 unit away from the waypoint (because you check for if(moveDirection.magnitude < 1) and not(moveDirection.magnitude < 0.1) for example, or it overshoots it because you're using the velocity of the rigidbody to move, and expecting the physics engine to stop it in time. Is your behaviour similar to what I'm describing? Or does it stop REALLY away from the next waypoint?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Henrique Vilela · May 05, 2011 at 01:36 PM

Looks like you're changing to the next waypoint too early. If you're using the right scale, 1 means 1 meter so try to use a smaller number like 0.1 (10 centimeters).

if (moveDirection.magnitude < 0.1) {
    // waipoint reached
}
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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Clearing a destination... 1 Answer

create shortest AI path from/to object. 1 Answer

Confused about copying Lists! 1 Answer

AI Waypoint help or suggestions!? 2 Answers


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