コード例 #1
0
    public override void _PhysicsProcess(float delta)
    {
        if (player != null)
        {
            if (rotateplayer.CurrentAnimation != "")
            {
                if (anim == 0 && rotateplayer.CurrentAnimationPosition > var1)
                {
                    rotateplayer.Stop(true);
                    player.RotationDegrees = degree;
                }
                else if (anim == 1 && rotateplayer.CurrentAnimationPosition > var2)
                {
                    rotateplayer.Stop(true);
                    player.RotationDegrees = targetdegree;
                }
            }

            if (player.IsOnFloor() && OverlapsArea(area) && isEvent && !isPlayerIn)
            {
                isPlayerIn = true;
            }
            if (player.IsOnFloor() && !OverlapsArea(area) && !isEvent && isPlayerIn)
            {
                isPlayerIn = false;
            }
        }
    }
コード例 #2
0
 public override void _PhysicsProcess(float delta)
 {
     if (_shouldGeneratePath && _owner.IsOnFloor())
     {
         GetNewPath();
     }
     else if (_targetCellId < _pathfindCells.Count)
     {
         var targetPos = GetTargetPosition();
         if (_owner.IsOnFloor() && _owner.GlobalPosition.DistanceSquaredTo(targetPos) <= MAX_AHEAD * MAX_AHEAD)
         {
             _targetCellId++;
         }
     }
 }
 public void Jump()
 {
     if (_kb.IsOnFloor())
     {
         _bufferedJumpAcceleration = _jumpImpulse;
     }
 }
コード例 #4
0
        public override void _PhysicsProcess(float delta)
        {
            if (!_owner.IsOnFloor())
            {
                return;
            }

            foreach (var area in GetOverlappingAreas())
            {
                if (area is EntitySeparatorComponent esc)
                {
                    var dir = new Vector2(Mathf.Sign(GlobalPosition.x - esc.GlobalPosition.x), 0f);
                    _velocityComponent.ApplyForce(dir, SEPARATION_FORCE * delta);
                }
            }
        }
コード例 #5
0
    public void Move(KinematicBody2D character, float delta)
    {
        inputVelocity.y += GravityScale * Gravity * delta;
        inputVelocity    = character.MoveAndSlide(inputVelocity, UP, true, 4, 0.785398f, false);

        if (UseHorizontalDamp)
        {
            float damp = AirDamp;

            if (character.IsOnFloor())
            {
                damp = FloorDamp;
            }

            inputVelocity.x *= damp;
        }
    }
    public void ProcessPhysics(float delta)
    {
        _elapsedTime += delta;

        if (_kb.IsOnFloor())
        {
            _groundedTimestamp = _elapsedTime;
        }

        // Acceleration
        if (_accelerateThisFrame)
        {
            int velocityDir = Mathf.Sign(_currentVelocity.x);

            if (velocityDir != 0 && velocityDir != _accelerationDir)
            {
                Decelerate(ref _currentVelocity.x, _accelerationDir, delta);
            }
            else
            {
                Accelerate(ref _currentVelocity.x, _accelerationDir, delta);
            }
        }

        // If the player isn't accelerating, apply friction.
        if (!_accelerateThisFrame)
        {
            _currentVelocity.x += CalculateCounterAcceleration(_previousVelocity.x, _frictionConstant, delta) * delta;
        }

        // Execute a jump if a jump has been buffered.
        if (CanJump())
        {
            _currentVelocity.y = -_jumpVelocity;
            _jumpBuffered      = false;
        }

        // Determine which gravity to apply.
        float gravityThisFrame     = _currentVelocity.y < 0f ? _jumpGravity : _fallGravity;
        float verticalAcceleration = gravityThisFrame;

        // INTEGRATE NEW VELOCITY
        _currentVelocity.y += verticalAcceleration * delta;
        _currentVelocity.x  = Mathf.Clamp(_currentVelocity.x, -_maxSpeed, _maxSpeed);

        // Applying computated velocity to KinematicBody.
        bool airborne = !_kb.IsOnFloor();

        _currentVelocity = _kb.MoveAndSlide(_currentVelocity, Vector2.Up);

        #region Debug logs
        // HORIZONTAL MOVEMENT RELATED DEBUG MESSAGES.
        //if (_previousVelocity.x == 0f && _bufferedHorizontalAccleration != 0f)
        //    GD.Print($"Started accelerating: {debugTime}");

        //if (_previousVelocity.x != 0f &&_bufferedHorizontalAccleration == 0f)
        //    GD.Print($"Stopped accelerating: {debugTime}");

        //if (Mathf.Abs(_previousVelocity.x) > 0f && _currentVelocity.x == 0f)
        //    GD.Print($"Stopped moving: {debugTime}");

        // JUMP RELATED DEBUG MESSAGES.
        //if (_jumpThisTick)
        //    GD.Print($"Jumped: {debugTime}");

        //if (_previousVelocity.y < 0f && _currentVelocity.y >= 0f)
        //    GD.Print($"Reached apex of jump: {debugTime}");

        //if (_kb.IsOnFloor() && airborne)
        //    GD.Print($"Landed: {debugTime}");
        #endregion

        _previousVelocity = _currentVelocity;

        // Resetting buffered values for next frame.
        _accelerateThisFrame = false;
        _accelerationDir     = 0;
    }
コード例 #7
0
 public bool IsJustLanded(KinematicBody2D body)
 {
     return(body.IsOnFloor() && !snap);
 }