Waypoint system

Hi i found this great waypoint script, but i would like to modify it a bit.

is it possible to put in if sentence in there like:

  • if i click on an object,
  • my current player position will be a waypoint,
  • the clicked object will be a waypoint
  • and my player will go to this spot,
  • when the player reaches the waypoint the waypoints will destroy themselfs.

thanks in advance!

var waypoint : Transform[];
var speed : float = 50;
private var currentWaypoint : int = 0;
var loop : boolean = true;
var player : Transform;
private var character : CharacterController;

function Start ()
{
    character = GetComponent(CharacterController);
}

function Update () 
{
    if(currentWaypoint < waypoint.length)
    {
        var target : Vector3 = waypoint[currentWaypoint].position;
        target.y = transform.position.y; // keep waypoint at character's height
        var moveDirection : Vector3 = target - transform.position;
        if(moveDirection.magnitude < 1)
        {
            transform.position = target; // force character to waypoint position
            currentWaypoint++;
        }
        else
        {
            transform.LookAt(target);
            character.Move(moveDirection.normalized * speed * Time.deltaTime);
        }
    }
    else
    {
        if(loop)
        {
            currentWaypoint=0;
        }
    }
}

has anyone an idea?

It is always problematic to use scripts from somebody else. What you are basically asking for here for is that somebody else rewrites this script to suit your needs. And this will not happen. Because then you will come back and ask for even more modifications.

You would be better suited when you would build your waypoint system from scratch. Divide your goals. First goal is to let a player rotate towards a waypoint. Second step is to let a player move towards the waypoint, and so on. You can of course use this script as a reference for that, and reuse the code snippets. But you need to understand what does what. Understanding is the key for further modifications.