Hi,
How would I go about moving through a set of waypoints using a keypress? I currently have it working but it is not very good at all. The character moves to the point and stops when it hits the trigger but if the collider on the waypoint or on the char is too large, it can require more than one press to get out of the collider. If its too small if will mess up and fly off the map.
The game I am making is for visually impaired people who have different levels of blindness and it uses text-to-speech to help guide them.
This is my script for waypoints and so on is this:
var waypoint : Transform[];
var speed : float = 20;
private var currentWaypoint : int;
var loop : boolean = true;
var isMoving : boolean = false;
var velocity : Vector3;
function Update () {
if(Input.anyKeyDown && isMoving == false)
{
isMoving = true;
}
if(currentWaypoint < waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
velocity = rigidbody.velocity;
transform.LookAt(target);
if(moveDirection.magnitude < 1)
{
if(isMoving != true)
{
currentWaypoint++;
}
}
if(isMoving == true)
{
animation.CrossFade("run");
velocity = moveDirection.normalized * speed;
rigidbody.velocity = velocity;
}
}
}
function OnTriggerStay(other : Collider)
{
if(other.tag == "wayPoint")
{
animation.Play("idle1");
rigidbody.velocity = Vector3(0,0,0);
isMoving = false;
}
}
Thanks!