- Home /
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);
}
}
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
Your answer
Follow this Question
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