Ejemplo n.º 1
0
        private void FixedUpdate()
        {
            if (isDead)
            {
                return;
            }

            // this just checks if the car's position is near enough to a waypoint to count as passing it, if it is, then change the target waypoint to the
            // next in the list.
            if (reachedDestination)
            {
                waypointNavigator.getNextWaypoint();

                // if after requesting a new waypoint we didnt get one, show stop signals
                showStopSignals(reachedDestination);

                if (reachedDestination)
                {
                    hardBrake();
                    return;
                }
            }

            //float mph = rigid.velocity.magnitude * 2.237f;

            // This is to limit the maximum speed of the car, adjusting the drag probably isn't the best way of doing it,
            // but it's easy, and it doesn't interfere with the physics processing.
            rigid.drag = rigid.velocity.magnitude / 250f;

            if (!gotCollisions())
            {
                int speed = currentWaypoint.minSpeed + UnityEngine.Random.Range(0, 20);

                if (speed > currentWaypoint.maxSpeed)
                {
                    speed = currentWaypoint.maxSpeed;
                }
                if (speed > maxSpeed)
                {
                    speed = maxSpeed;
                }
                moveToWaypoint(speed);

                sense = getSense(destination - transform.position);
            }
            else
            {
                status = Status.Stopped;
            }
        }
Ejemplo n.º 2
0
        private void Update()
        {
            if (reachedDestination)
            {
                waypointNavigator.getNextWaypoint();

                // if after requesting a new waypoint we didnt get one, stop moving animation
                if (reachedDestination)
                {
                    animator.SetFloat("Speed", 0);
                    return;
                }
            }

            Vector3 direction = destination - transform.position;

            animator.SetFloat("Speed", movementSpeed);
            transform.position = Vector3.MoveTowards(transform.position, destination, Time.deltaTime * movementSpeed);

            if (direction != Vector3.zero)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), Time.deltaTime * 4);
            }
        }