Hi everyone,
My 3D game has a NPC sprite moving towards it's target object and stopping once it reaches it.
I'm after some help on how to prevent the sprite moving diagonally. I understand it must be something like using GetAxis and telling the object to not move on the x-axis if the y-axis has movement but I just can't figure it out exactly. With my player, putting a "return;" after each of it's movement inputs did the job perfectly but I believe that doesn't really apply to this because I'm not specifically addressing each direction of Vector3 movement right?
Apologies for my very amateur coding knowledge. I'd hate to be one of those people on here who asks silly questions and tries to get people to do it for them. I've been stuck on this for a couple hours however and couldn't solve it looking at all the other questions on this lovely site or others...
Here's my code:
Thanks a lot :)
#pragma strict
var target: Transform;
var speed: float;
var thereyet: boolean;
function Start(){
thereyet = false;
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag=="Position_1"){
thereyet = true;
}
}
function OnTriggerExit (other : Collider) {
if(other.gameObject.tag=="Position_1"){
thereyet = false;
}
}
function Update(){
if (thereyet == false){
var step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}
↧