示例#1
0
    void ShadowPlayerUpdate()
    {
        // maybe change logic here?
        destination = player.position + targetDirectionFromPlayer * distanceToMaintain;

        Vector3 movement = destination - this.transform.position;

        movement = movement.normalized * moveSpeed * shadowSpeedCoefficient * Time.fixedDeltaTime;

        // if we're close enough, don't overshoot
        if (UsefulStuff.CloseEnough(this.transform.position, destination, movement.sqrMagnitude))
        {
            movement = destination - this.transform.position;
        }
        else if (UsefulStuff.FarEnough(this.transform.position, destination, tooFarAway * tooFarAway))
        {
            BeginCatchUpToPlayer();
        }

        base.MoveWithSliding(
            new Vector3(
                movement.x,
                movement.y,
                0));
    }