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 john 2 · Aug 25, 2010 at 12:57 PM · javascriptaiwaypointenemyai

AI Waypoint help or suggestions!?

i wanna know how to make a script that has two GameObject variables, waypoint1 and waypoint2, which then tells the object the script will be attached to, to walk back and forth in between the waypoints.please help! all help is Greatly appreciated!!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Aug 25, 2010 at 01:03 PM

Take a look at the Spline Controller script on the wiki - you can set up two (or possibly more, so that turning looks better at the ends) control points and have your object walk between them

http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller

Preferably download the c# version, as it has less bugs than the js version (and is 3.0 compatible if I remember correctly) - and looking at the site again, maybe even the iPhone compatible version, as it's got another fix in

Comment
Add comment · Show 1 · 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
avatar image john 2 · Aug 25, 2010 at 03:25 PM 0
Share

Thanks, $$anonymous$$an thats exactly what i wanted!

avatar image
0

Answer by oinkoinkflapflap · Dec 04, 2010 at 01:23 PM

i got most of the following from a great youtube vid, but here are the scripts and instructions and stuff

make an empty game object, call it "waypoint" or whatevers easy and attatch this 2 it you can see it on creating but not on game which is handy :).

function OnDrawGizmos(){

Gizmos.DrawIcon(transform.position,"AITuts/Materials/Textures/WayPoint");

}

ok then put this were u want it 2 move. put the following on what you want to go there (your AI)

var waypoint : Transform[];

var speed : float = 20;

private var currentWaypoint : int;

var loop : boolean = true;

function Awake(){

waypoint[0] = transform;

} 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(loop){ currentWaypoint=0; } else{ velocity = Vector3.zero; } }

rigidbody.velocity = velocity;

}

then add a "rigidbody" to your AI (it's best 2 use a sphere or a capsule for were you attach your script)

then on the object click the name "waypoint" and change the "size" number to how ever many waypoints you want. with the waypoints i explained earlier drag them into the empty slots. when it gets to the end it should do a loop, if it doesn't make the size 1 bigger and but the 1 before the last to the end, if this is a bit confusing i recommend the youtube vid (link at the end) there are 3 vids in the series that will help with what i explained if you want it to point and shoot, say and i can help with that 2 :)

http://www.youtube.com/user/steamisM50#p/a/DC891A19DE6D2322/0/POUbAsr-6q4

this guy helps.........

Comment
Add comment · Show 1 · 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
avatar image oinkoinkflapflap · Dec 04, 2010 at 01:24 PM 0
Share

there r bits of scripts here that arn't in colours, so dont forget them! ;)

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

Waypoint System help 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

create shortest AI path from/to object. 1 Answer

How to make the enemy move back to its waypoint after it's target killed? 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