Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(waypoints[currentWaypoint], transform.position) < 1.0f)
        {
            currentWaypoint = (currentWaypoint + 1) % waypoints.Count;
        }
        Vector3 desired = waypoints[currentWaypoint] - transform.position;

        desired.Normalize();
        desired *= maxSpeed;
        Vector3 force = desired - velocity;

        Vector3 acceleration = force / mass;

        velocity += acceleration * Time.deltaTime;
        transform.Translate(velocity * (Time.deltaTime * 4), Space.World);
        transform.forward = velocity;
        checkDeath();
        if (gameObject.transform.position.z < -20)
        {
            CoreBehaviour.takeHealth(damage);
            Debug.Log("Death by position");
            Destroy(this.gameObject);
            done = true;
        }
    }