Exemple #1
0
 public bool Sensed()
 {
     return(RayCastData.SurroundingCasts[ray].colliding && PlayerAreaSensor.GetArea(sensorDirection));
 }
Exemple #2
0
    public override void Update(float delta)
    {
        base.Update(delta);
        Vector3 finalMove = Vector3.Zero;
        Vector3 snapDown  = Vector3.Zero;

        //All things that happen when the player is on the ground
        if (groundColliding)
        {
            //For when the player stops moving.
            if (!controller.inputs.moved)
            {
                if (currentSpeed < .1f)
                {
                    switch (controller.ability.GetCurrentState())
                    {
                    case PlayerState.sprinting:
                    case PlayerState.walking:
                        Stop();
                        SetState(PlayerState.standing);
                        break;

                    case PlayerState.crouch:
                        Stop();
                        break;
                    }
                }
                if (controller.ability.GetCurrentState() != PlayerState.slide)
                {
                    if (currentSpeed < .1f)
                    {
                        currentSpeed = 0;
                    }
                    else
                    {
                        currentSpeed -= currentSpeed * time * PlayerOptions.walkingDeceleration;
                    }
                }
            }
            else //This is what happens when they do move
            {
                //This section is for changing the players state
                if (controller.size.crouched)
                {
                    if (accelerate > 1.1f)
                    {
                        SetState(PlayerState.slide);
                    }
                    else
                    {
                        SetState(PlayerState.crouch);
                    }
                }
                else
                {
                    if (maxSpeed == PlayerOptions.playerMaxWalkingSpeed)
                    {
                        SetState(PlayerState.walking);
                    }
                    else
                    {
                        SetState(PlayerState.sprinting);
                    }
                }
            }

            //Testing whether we need to modify the angle that the player walks
            if (!groundData.colliding || controller.ability.GetNoCollide())
            {
                finalMove += stableMove.Normalized() * currentSpeed * accelerate;
                //This is the mod that allows walking up slopes needs to be zero'd out when not in use
                verticalAddition *= 0;
            }
            else
            {
                //The mod being calculated
                verticalAddition = groundData.normal.Cross(stableMove.Rotated(Vector3.Up, NinetyDegreesToRad)).Normalized();
                finalMove       += verticalAddition * currentSpeed * accelerate;
            }
            //Used primarely quick bursts of speed but drops when on the ground
            horizontalAcc -= horizontalAcc * time * .9f;

            //Universal knockback that only starts to slow when on the ground
            if (knockback.Length() < .1f)
            {
                knockback *= 0;
            }
            else
            {
                knockback -= knockback * time * 2f;
            }

            if (verticalMove.Length() < 0.01f)
            {
                snapDown = Vector3.Down;
            }
        }
        else //No longer on the ground
        {
            //This sets the state to falling up and down so long as the player isnt' wall running or gliding
            if (controller.ability.GetCurrentState() != PlayerState.wallRunning && controller.ability.GetCurrentState() != PlayerState.glide)
            {
                if (verticalMove.y > 0)
                {
                    SetState(PlayerState.fallingUp);
                }
                else
                {
                    SetState(PlayerState.fallingDown);
                }
            }
            //For when the player is in the air and is moving
            finalMove += stableMove * accelerate;

            //Controlling the vertical movement of the player depending on the state they are currently in
            switch (controller.ability.GetCurrentState())
            {
            case PlayerState.wallRunning:
                verticalMove += Vector3.Down * time * PlayerOptions.wallRunningGravity;
                break;

            case PlayerState.glide:
                verticalMove = Vector3.Down * PlayerOptions.glideFallSpeed;
                break;

            default:
                verticalMove += Vector3.Down * time * PlayerOptions.gravity;
                break;
            }
        }
        //Some edge cases where the player is on the ground and gets hit with knockback or something that modifies vertical move
        if (PlayerAreaSensor.GetArea(AreaSensorDirection.Above) && verticalMove.y > 0)
        {
            verticalMove = Vector3.Zero;
        }
        finalMove += horizontalAcc + verticalMove + pushing + knockback;
        //Moves the player finally
        controller.MoveAndSlideWithSnap(finalMove, snapDown, Vector3.Up, true);
        //Will only work if you have a force applying downward to the character?
        if (controller.IsOnFloor() != onFloor)
        {
            onFloor = controller.IsOnFloor();
            controller.GroundChanging(onFloor);
            floorMovement.y = controller.GetFloorVelocity().y;
        }
        if (currentAccelerationTime < PlayerOptions.slideMaxTime)
        {
            currentAccelerationTime += time;
        }
        else
        {
            accelerate = Mathf.Clamp(accelerate - PlayerOptions.slideDeceleration * time, 1, accelerate);
        }
        pushing = Vector3.Zero;
        if (controller.ability.GetCurrentState() != PlayerState.slide)
        {
            if (moved)
            {
                movedBuffer += 1;
                if (movedBuffer > 60f - Engine.GetFramesPerSecond())
                {
                    moved       = false;
                    movedBuffer = 0f;
                }
            }
        }
    }
Exemple #3
0
 public bool CanJump()
 {
     return(((controller.upgrades.GetUpgrade(PlayerUpgrade.DoubleJump) && !DoubleJumpUsed) ||
             (controller.upgrades.GetUpgrade(PlayerUpgrade.TripleJump) && !tripleJumpUsed) ||
             cayoteTime < PlayerOptions.cayoteMaxTime) && !PlayerAreaSensor.GetArea(AreaSensorDirection.Above));
 }