I have the following code but it doesn’t go straight down (My camera’s blue arrow is faced down), it makes the enemies go off to the side. What am I doing wrong. Thanks!
var newPos : Vector3;
var Destination : Vector3;
var EmptyObject : Transform;
var HitObject : GameObject;
var particle : GameObject;
var Enemies;
function Start () {
newPos = gameObject.transform.position;
}
function Update () {
if(Input.GetKey(KeyCode.D)){
newPos.x = newPos.x + 1;
gameObject.transform.position = newPos;
}
if(Input.GetKey(KeyCode.A)){
newPos.x = newPos.x - 1;
gameObject.transform.position = newPos;
}
if(Input.GetKey(KeyCode.W)){
newPos.z = newPos.z + 1;
gameObject.transform.position = newPos;
}
if(Input.GetKey(KeyCode.S)){
newPos.z = newPos.z - 1;
gameObject.transform.position = newPos;
}
var hit : RaycastHit;
if(Input.GetKeyDown(KeyCode.E)){
if(Physics.Raycast (gameObject.transform.position, transform.forward, hit, Mathf.Infinity)){
Enemies = GameObject.FindGameObjectsWithTag("Enemy");
print("Got past the Enemies = GameObject");
for (var Enemy in Enemies){
Enemy.GetComponent("Enemy").SendMessage("GoToPosition", hit.transform.position);
print("Got to the HitObject.GetComponent!");
}
}
}
}