void GroundMovementUpdate() { //check if is on ground //State = p_Controller.isGrounded ? State | CCState.IsGrounded : State & ~CCState.IsGrounded; State = (Collisions & CC_Collision.CollisionBelow) != 0 ? State | CC_State.IsGrounded : State & ~CC_State.IsGrounded; if (!IsGrounded) { State &= ~CC_State.OnPlatform; // remove platform if on air } jumpGraceTimer = Mathf.Clamp(jumpGraceTimer - 1, 0, CPMSettings.JumpGraceTime); // check if above a platform //if (PhysicsExtensions.CapsuleCast(ownCollider, -transform.up, out platformHit, ownCollider.height, PlatformLayer)) // State |= CC_State.OnPlatform; //else // State &= ~CC_State.OnPlatform; //OnPlatform = Physics.Raycast(transform.position, -transform.up, out platformHit, p_Controller.height, PlatformLayer); // player moved the character var walk = inputDir.y * transform.TransformDirection(Vector3.forward); var strafe = inputDir.x * transform.TransformDirection(Vector3.right); wishdir = (walk + strafe); float step = YawRot * CPMSettings.RotateVelocity * Time.deltaTime; wishdir = Quaternion.Euler(0, 10 * YawRot, 0) * wishdir; wishdir.Normalize(); // only apply friction on groud for the last frame it was grounded if (wasGrounded) { Velocity = MoveGround(wishdir, Velocity); } else { // apply air movement Velocity = MoveAir(wishdir, Velocity); } // jumping window for bunnyhopping if (triedJumping > 0) { // normal jump, it's on the ground if (IsGrounded || jumpGraceTimer > 0) { //p_velocity += Vector3.up * CPMSettings.JumpVelocity; Velocity.y = CPMSettings.JumpVelocity; triedJumping = 0; jumpGraceTimer = 0; sprintJump = Sprint; OnJump.Invoke(); } } CalculateGravity(); CharacterMove(Velocity); // player just got off ground if (wasGrounded && !IsGrounded) { // falling if (Velocity.normalized.y < 0) { jumpGraceTimer = CPMSettings.JumpGraceTime; } } triedJumping = Mathf.Clamp(triedJumping - 1, 0, 100); // notify when player reaches the gorund if (!wasGrounded && IsGrounded) { //if (OnPlatform) //{ // p_velocity = Friction(p_velocity, 20); //} Vector3 friction = Friction(Velocity, 20); Velocity.x = friction.x; Velocity.z = friction.z; jumpGraceTimer = 0; sprintJump = false; OnLanding.Invoke(); } wasGrounded = IsGrounded; wasOnPlatform = OnPlatform; }
public void AddState(CC_State state) { State |= state; }
public void RemoveState(CC_State state) { State &= ~state; }
public bool HasState(CC_State state) { return((State & state) != 0); }