void FixedUpdate() { // Check if on a solid surface grounded = (collisionFlags & CollisionFlags.Below) != 0; // Clear movement if (cancelMovement) { moveDirection = Vector3.zero; cancelMovement = false; groundMotor.ClearActivePlatform(); acrobatMotor.ClearFallingDamage(); return; } // Handle freeze movement if (freezeMotor > 0) { freezeMotor -= Time.deltaTime; if (freezeMotor <= 0) { freezeMotor = 0; CancelMovement = true; } return; } playerScanner.FindHeadHit(new Ray(controller.transform.position, Vector3.up)); playerScanner.SetHitSomethingInFront(); // Check if should hang hangingMotor.HangingChecks(); // Handle Rappeling rappelMotor.RappelChecks(); // Handle climbing climbingMotor.ClimbingCheck(); // Do nothing if player levitating/swimming or climbing - replacement motor will take over movement for levitating/swimming if (levitateMotor && (levitateMotor.IsLevitating || levitateMotor.IsSwimming) || climbingMotor.IsClimbing || hangingMotor.IsHanging) { moveDirection = Vector3.zero; return; } if (climbingMotor.WallEject) { // True in terms of the player having their feet on solid surface. grounded = true; } if (grounded) { acrobatMotor.Jumping = false; acrobatMotor.CheckFallingDamage(); // checks if sliding and applies movement to moveDirection if true frictionMotor.GroundedMovement(ref moveDirection); acrobatMotor.HandleJumpInput(ref moveDirection); } else { acrobatMotor.CheckInitFall(ref moveDirection); acrobatMotor.CheckAirControl(ref moveDirection, speed); } playerScanner.FindStep(moveDirection); acrobatMotor.ApplyGravity(ref moveDirection); acrobatMotor.HitHead(ref moveDirection); groundMotor.MoveWithMovingPlatform(moveDirection); }
void FixedUpdate() { // Clear movement if (cancelMovement) { moveDirection = Vector3.zero; cancelMovement = false; groundMotor.ClearActivePlatform(); acrobatMotor.ClearFallingDamage(); return; } // Handle freeze movement if (freezeMotor > 0) { freezeMotor -= Time.deltaTime; if (freezeMotor <= 0) { freezeMotor = 0; CancelMovement = true; } return; } // Handle climbing climbingMotor.ClimbingCheck(ref collisionFlags); if (climbingMotor.IsClimbing) { acrobatMotor.Falling = false; } // Do nothing if player levitating/swimming or climbing - replacement motor will take over movement for levitating/swimming if (levitateMotor && (levitateMotor.IsLevitating || levitateMotor.IsSwimming) || climbingMotor.IsClimbing) { return; } // Player assumed to be in movement for now standingStill = false; if (grounded) { // Set standing still while grounded flag // Casting moveDirection to a Vector2 so constant downward force of gravity not included in magnitude standingStill = (new Vector2(moveDirection.x, moveDirection.z).magnitude == 0); acrobatMotor.Jumping = false; acrobatMotor.CheckFallingDamage(); // checks if sliding and applies movement to moveDirection if true frictionMotor.MoveIfSliding(ref moveDirection); acrobatMotor.HandleJumpInput(ref moveDirection); } else { acrobatMotor.CheckInitFall(); acrobatMotor.CheckAirControl(ref moveDirection, speed); } acrobatMotor.ApplyGravity(ref moveDirection); // If we hit something above us AND we are moving up, reverse vertical movement if ((controller.collisionFlags & CollisionFlags.Above) != 0) { if (moveDirection.y > 0) { moveDirection.y = -moveDirection.y; } } groundMotor.MoveOnGround(moveDirection, ref collisionFlags, ref grounded); }