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 asdf1234 · Apr 09, 2011 at 01:49 AM · javascriptaiitweenwaypointmoveto

iTween Help Please MoveTo not working

Hi, I am currently trying to program an AI script in JavaScript and I decided to use itween for the walking between waypoints and it seems to not like my itween script section. The problem is in the function Update () section, specifically the 4 "if (waypointSelect == X) { ........}" Im really not that good at itween and i did try the tutorials for moveTo like iTween.MoveTo(gameObject{"y": 1, time: 1} ) but it wouldn't take it. So is there any way to alter the script where the problem is to make it do what i want it to do (go to the waypoints)?

var isShooting = false; var isWalking = false; var isNearPlayer = false; var LookAtTarget : Transform; var waypointSelect = 0; var prefabBullet : GameObject; var shootForce : float = 7000; var Player : Transform; var DistToPlayer : float; var Waypoint1 : Transform; var Waypoint2 : Transform; var Waypoint3 : Transform; var Waypoint4 : Transform;

function Shoot () {

     var instanceBullet = Instantiate(prefabBullet, transform.position, transform.rotation); 
     instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
     }

function ShootIng () {

 if (isShooting == true) {
     transform.LookAt(LookAtTarget);
     InvokeRepeating("Shoot", 1, 0.5);
     }
     else
     {
         CancelInvoke("Shoot");
     }

}

function Walking () {

 if (isWalking == true) {    
 waypointSelect = (Random.Range(1, 4));
 }

}

function AIControl () {

 if (isNearPlayer == true) {
     Invoke("Shooting", 0.5);
     WaitForSeconds (6);
         Invoke("Walking", 0.5);
     }
     else
     {
         CancelInvoke("Shooting");
         CancelInvoke("Walking");
     }

}

function Update () {

 if (Player) {
     var dist = Vector3.Distance(Player.position, transform.position);
     DistToPlayer = (dist);
     }

 if (waypointSelect == 1) {
     iTween.MoveTo(Waypoint1);
     }

 if (waypointSelect == 2) {
     iTween.MoveTo(Waypoint2);
     }

 if (waypointSelect == 3) {
     iTween.MoveTo(Waypoint3);
     }

 if (waypointSelect == 4) {
     iTween.MoveTo(Waypoint4);
     }

 if (DistToPlayer < 10) {
     isNearPlayer = true;
     }
     else
     {
         isNearPlayer = false;
     }


 if (isNearPlayer == true) {
     Invoke("AIControl", 0.5);
     }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Joakim · Dec 22, 2012 at 11:13 PM

Check if your if's really execute and do you call iTween properly

 if(waypointSelected == 1)
    Debug.Log("Waypoint 1 selected");
    iTween.MoveTo(yourobject.gameObject, waypoint1.position, 2f);
    //alternatively call it with Hash parameter, check the iTween documentation

You should see the message in the console, and if you select new waypoint, new iTween call will kill the first call and continue moving in new direction.

Hope this helps.

Joakim

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

1 Person is following this question.

avatar image

Related Questions

How do I create a simply disable script for enemy AI once it completes its waypoints? 2 Answers

How to make enemy attack multiple unit rather then single?(updated) 1 Answer

How to move an object on a random path with iTween 1 Answer

What should I do? Disable the AI or have the AI simply be recylced and reused? 1 Answer

Kind of Patrol AI with Point A and B Help 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