Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Gameobject not moving unless starting at 0 transform

$
0
0
I'm making a 2d game where the enemy is assigned a array of vector3's in the editor. That way I can set it's path along a grid of units that it moves to in a blocky way. It was working well but, after I changed the orgin point of the enemy gameobject off of 1,0,0 it doesn't work. I couldn't find any noticeable changes in any values while looking in the debug menu and I attempted to use some debug logs but they also didn't reveal anything. Note: I am using unity 4 as that's all my laptop supports. Code: using UnityEngine; using System.Collections; public class EnemyMovementController : MonoBehaviour { //Set in editor by level basis, holds pathfinding data for enemy. public Vector3[] EnemyPathArray; //Path segment in the Enemy Path Array. int PathSegmentArray; //Speed for movement; public float EnemyMovementSpeed; //Timer on when the enemy moves. float Speed; float EnemyMoveTimer; //Temp float for testing the time between moves for ideal timeing. public float EnemyMoveTimerCapTemp; //Bool for moving enemy bool EnemyMoving; //Movement Array for enemy position. public GameObject Enemy; void Start(){ EnemyMoveTimer = EnemyMoveTimerCapTemp; PathSegmentArray = 0; } void Update(){ if (!EnemyMoving) { EnemyMoveTimer -= Time.deltaTime; if (EnemyMoveTimer <= 0) { EnemyMoving = true; } } if (EnemyMoving) { Speed = EnemyMovementSpeed * Time.deltaTime; MoveEnemy(); } } void MoveEnemy(){ //Debug.Log ("Moving Enemy"); Debug.Log (PathSegmentArray); Enemy.transform.position = Vector3.MoveTowards (Enemy.transform.position, EnemyPathArray [PathSegmentArray], Speed); //Debug.Log (test + "this.transform"); //Debug.Log (EnemyPathArray [PathSegmentArray].y + "Target transform"); if (Enemy.transform.position == EnemyPathArray [PathSegmentArray]) { PathSegmentArray += 1; if(PathSegmentArray > EnemyPathArray.Length - 1){ PathSegmentArray = 0; //Debug.Log("Setting path segment to 0"); } EnemyMoveTimer = EnemyMoveTimerCapTemp; EnemyMoving = false; } } }

Viewing all articles
Browse latest Browse all 1488

Latest Images

Trending Articles



Latest Images