示例#1
0
    private void DropToPlanet()
    {
        if (_dude.State != Dude.DudeState.Falling || !Planet)
        {
            return;
        }

        var distance = Vector3.Distance(transform.position, Planet.transform.position);

        if (distance < Planet.Radius)
        {
            if (_dude.State == Dude.DudeState.Falling)
            {
                SnapToSurface();
                _dude.SetState(Dude.DudeState.Idle);
                _dude.FindNewTarget();
            }
        }

        var vectorFromPlanet = (transform.position - Planet.transform.position).normalized;

        transform.position = Planet.transform.position + vectorFromPlanet * (distance - Time.deltaTime * _fallingSpeed);
    }