Exemple #1
0
    protected void FixedUpdate()
    {
        GetInfo();

        AccelerationOutput acceleration = GetAcceleration();

        if (acceleration != null)
        {
            rotation += acceleration.angular * Time.fixedDeltaTime;

            if (rotation > maxRotation)
            {
                rotation = Math.Sign(rotation) * maxAngularAcceleration;
            }

            character.transform.rotation = Quaternion.Euler(
                character.transform.rotation.eulerAngles.x,
                character.transform.rotation.eulerAngles.y + (rotation * Time.fixedDeltaTime),
                character.transform.rotation.eulerAngles.z
                );

            velocity += acceleration.linear * Time.fixedDeltaTime;

            if (velocity.magnitude > maxSpeed)
            {
                velocity = velocity.normalized * maxSpeed;
            }

            transform.position += velocity * Time.fixedDeltaTime;
        }
        else
        {
            rotation = 0f;
        }
    }
    protected void FixedUpdate()
    {
        GetInfo();

        AccelerationOutput acceleration = GetAcceleration();

        if (acceleration != null)
        {
            rotation += acceleration.angular * Time.fixedDeltaTime;

            if (rotation > maxRotation)
            {
                rotation = Math.Sign(rotation) * maxAngularAcceleration;
            }

            character.transform.rotation = Quaternion.Euler(
                character.transform.rotation.eulerAngles.x,
                character.transform.rotation.eulerAngles.y + (rotation * Time.fixedDeltaTime),
                character.transform.rotation.eulerAngles.z
                );
        }
        else
        {
            rotation = 0f;
        }
    }
    protected void FixedUpdate()
    {
        GetInfo();

        AccelerationOutput acceleration = GetAcceleration();

        velocity += acceleration.linear * Time.fixedDeltaTime;

        character.transform.position += velocity * Time.fixedDeltaTime;
    }
Exemple #4
0
    // Get the acceleration in 3D
    protected virtual AccelerationOutput GetAcceleration()
    {
        AccelerationOutput steering = new AccelerationOutput();

        steering.linear = character.transform.position - targetPosition;

        steering.linear.Normalize();
        steering.linear *= maxAcceleration;

        steering.angular = 0;

        return(steering);
    }
    // Get the acceleration in 3D
    protected virtual AccelerationOutput GetAcceleration()
    {
        AccelerationOutput acceleration = new AccelerationOutput();

        acceleration.linear = target.transform.position - character.transform.position;

        acceleration.linear.Normalize();
        acceleration.linear *= maxAcceleration;

        acceleration.angular = 0;

        return(acceleration);
    }
    protected virtual AccelerationOutput GetAcceleration()
    {
        AccelerationOutput acceleration = new AccelerationOutput();

        acceleration.linear  = targetVelocity - characterVelocity;
        acceleration.linear /= timeToTarget;

        if (acceleration.linear.magnitude > maxAcceleration)
        {
            acceleration.linear.Normalize();
            acceleration.linear *= maxAcceleration;
        }

        acceleration.angular = 0f;

        return(acceleration);
    }
    // Returns a SteeringOutput object who's linear vector is the acceleration amount for this frame
    protected override AccelerationOutput GetAcceleration()
    {
        AccelerationOutput acceleration;
        Vector3            direction;
        Vector3            desiredVelocity;
        float distance;
        float targetSpeed;

        acceleration = new AccelerationOutput();

        // Direction and distance from character to target
        direction = targetPosition - character.transform.position;
        distance  = direction.magnitude;

        // Stores the desired movement speed of the object
        targetSpeed = 0f;

        // If the distance is within the stopping radius, return null
        if (distance < targetRadius)
        {
            return(null);
        }
        // If the distance is outside the slow down radius, move at max speed
        else if (distance > slowRadius)
        {
            targetSpeed = maxSpeed;
        }
        // If the distance is within the slow down radius, calculate the speed based on distance from the target
        else
        {
            targetSpeed = maxSpeed * distance / slowRadius;
        }

        // Normalize the direction we want to move in and multiply it by the target speed
        desiredVelocity = direction;
        desiredVelocity.Normalize();
        desiredVelocity *= targetSpeed;

        characterVelocity = velocity;
        targetVelocity    = desiredVelocity;

        // Now that the character and target velocities have been calculated, simply call
        // the function in MatchVelocity
        return(base.GetAcceleration());
    }
    protected virtual AccelerationOutput GetAcceleration()
    {
        acceleration = new AccelerationOutput();
        print(targetOrientation);
        // Map the forward directions to degree orientations, subtract the forward orientations to get the
        // rotational difference between them, then convert that difference back to radians (-Pi, Pi]
        rotationRemaining = Math.MapPiToDegrees(targetOrientation) - Math.MapPiToDegrees(characterOrientation);
        rotationRemaining = Math.MapDegreesToPi(rotationRemaining);

        // Get the magnitude of the rotation
        rotationRemainingSize = Mathf.Abs(rotationRemaining);

        if (rotationRemainingSize < targetRadius)
        {
            return(null);
        }
        else if (rotationRemainingSize > slowRadius)
        {
            targetRotation = maxRotation;
        }
        else
        {
            targetRotation = maxRotation * rotationRemainingSize / slowRadius;
        }

        targetRotation *= Math.Sign(rotationRemaining);

        acceleration.angular  = targetRotation - rotation;
        acceleration.angular /= timeToTarget;

        if (Mathf.Abs(acceleration.angular) > maxAngularAcceleration)
        {
            acceleration.angular /= Mathf.Abs(acceleration.angular);
            acceleration.angular *= maxAngularAcceleration;
        }

        acceleration.linear = Vector3.zero;

        return(acceleration);
    }
    protected void FixedUpdate()
    {
        GetInfo();

        AccelerationOutput acceleration = GetAcceleration();

        if (acceleration != null)
        {
            velocity += acceleration.linear * Time.fixedDeltaTime;

            if (velocity.magnitude > maxSpeed)
            {
                velocity = velocity.normalized * maxSpeed;
            }

            character.transform.position += velocity * Time.fixedDeltaTime;
        }
        else
        {
            velocity = Vector3.zero;
        }
    }