protected override void RefreshCollInfo() { //plank check, see if we need to ignore it if (plankLayer != 0 && !mPlankIsIgnore) { //check if there's a coll that is a plank bool plankFound = false; CollisionFlags plankCollFlag = CollisionFlags.None; for (int i = 0; i < mCollCount; i++) { CollideInfo inf = mColls[i]; if (inf.collider == null || inf.collider.gameObject == null || !inf.collider.gameObject.activeInHierarchy) { RemoveColl(i); i--; } else if (((1 << inf.collider.gameObject.layer) & plankLayer) != 0) { plankFound = true; plankCollFlag = inf.flag; if (plankCollFlag != CollisionFlags.Below) { RemoveColl(i); i--; } } } if (plankFound) { if (plankCollFlag == CollisionFlags.Below) { //check if we are ready to drop if (plankEnableDrop && mMoveYGround < 0.0f && Time.fixedTime - mMoveYGroundDownLastTime >= plankDropDelay) { SetPlankingIgnore(true); } } else { SetLocalVelocityToBody(); //revert rigidbody's velocity :P SetPlankingIgnore(true); } } else if (isGrounded && mMoveYGround < 0.0f) { mMoveYGround = 0.0f; } } base.RefreshCollInfo(); //bool isGroundColl = (mCollFlags & CollisionFlags.Below) != 0; if (mIsOnPlatform) { mCollFlags |= CollisionFlags.Below; mCollGroundLayerMask |= mIsOnPlatformLayerMask; } bool lastWallStick = mWallSticking; mWallSticking = false; if (isSlopSlide) { //Debug.Log("sliding"); mLastGround = false; mJumpCounter = jumpCounter; } //refresh wallstick else if (wallStick && !mJumpingWall && collisionFlags == CollisionFlags.Sides) { //check if we are going up if (!wallStickDownOnly || localVelocity.y <= 0.0f) { Vector3 up = dirHolder.up; if (collisionFlags == CollisionFlags.Sides) { for (int i = 0; i < mCollCount; i++) { CollideInfo inf = mColls[i]; if (inf.flag == CollisionFlags.Sides && (wallStickInvalidMask == 0 || ((1 << inf.collider.gameObject.layer) & wallStickInvalidMask) == 0)) { float a = Vector3.Angle(up, inf.normal); if (a >= 90.0f - wallStickAngleOfs && a <= 90.0f + wallStickAngleOfs) { //wallStickForce mWallStickCollInfo = inf; mWallStickSide = M8.MathUtil.CheckSide(mWallStickCollInfo.normal, dirHolder.up); mWallSticking = true; break; } } } } } if (mWallSticking) { if (wallStickPush) { if (CheckWallStickIn(moveSide)) { if (!mWallStickWaitInput) { //cancel horizontal movement Vector3 newVel = localVelocity; newVel.x = 0.0f; //reduce downward speed if (newVel.y < -wallStickDownSpeedCap) { newVel.y = -wallStickDownSpeedCap; } rigidbody.velocity = dirHolder.rotation * newVel; mWallStickLastTime = Time.fixedTime; mWallStickWaitInput = true; } mWallStickLastInputTime = Time.fixedTime; } else { bool wallStickExpired = Time.fixedTime - mWallStickLastInputTime > wallStickDelay; if (wallStickExpired) { mWallStickWaitInput = false; mWallSticking = false; } } } else { bool wallStickExpired = Time.fixedTime - mWallStickLastTime > wallStickDelay; //see if we are moving away if ((wallStickExpired && CheckWallStickMoveAway(moveSide))) { if (!mWallStickWaitInput) { mWallSticking = false; } } else if (!lastWallStick) { mWallStickWaitInput = true; mWallStickLastTime = Time.fixedTime; //cancel horizontal movement Vector3 newVel = localVelocity; newVel.x = 0.0f; //reduce downward speed if (newVel.y < -wallStickDownSpeedCap) { newVel.y = -wallStickDownSpeedCap; } rigidbody.velocity = dirHolder.rotation * newVel; } } } if (mWallSticking != lastWallStick) { if (mWallSticking) { mJump = false; lockDrag = false; } else { if (wallStickPush) { mWallStickWaitInput = false; } } } } if (mLastGround != isGrounded) { if (!mLastGround) { //Debug.Log("landed"); //mJump = false; //mJumpingWall = false; mJumpCounter = 0; if (localVelocity.y <= 0.0f) { if (landCallback != null) { landCallback(this); } } } else { //falling down? /*if(mJumpCounter <= 0) * mJumpCounter = 1;*/ mJumpLastTime = Time.fixedTime; mLastGroundTime = Time.fixedTime; } mLastGround = isGrounded; } }
protected override void RefreshCollInfo() { //plank check, see if we need to ignore it if(plankLayer != 0 && !mPlankIsIgnore) { //check if there's a coll that is a plank bool plankFound = false; CollisionFlags plankCollFlag = CollisionFlags.None; for(int i = 0; i < mCollCount; i++) { CollideInfo inf = mColls[i]; if(inf.collider == null || inf.collider.gameObject == null || !inf.collider.gameObject.activeInHierarchy) { RemoveColl(i); i--; } else if(((1 << inf.collider.gameObject.layer) & plankLayer) != 0) { plankFound = true; plankCollFlag = inf.flag; if(plankCollFlag != CollisionFlags.Below) { RemoveColl(i); i--; } } } if(plankFound) { if(plankCollFlag == CollisionFlags.Below) { //check if we are ready to drop if(plankEnableDrop && mMoveYGround < 0.0f && Time.fixedTime - mMoveYGroundDownLastTime >= plankDropDelay) { SetPlankingIgnore(true); } } else { SetLocalVelocityToBody(); //revert rigidbody's velocity :P SetPlankingIgnore(true); } } else if(isGrounded && mMoveYGround < 0.0f) { mMoveYGround = 0.0f; } } base.RefreshCollInfo(); //bool isGroundColl = (mCollFlags & CollisionFlags.Below) != 0; if(mIsOnPlatform) { mCollFlags |= CollisionFlags.Below; mCollGroundLayerMask |= mIsOnPlatformLayerMask; } bool lastWallStick = mWallSticking; mWallSticking = false; if(isSlopSlide) { //Debug.Log("sliding"); mLastGround = false; mJumpCounter = jumpCounter; } //refresh wallstick else if(wallStick && !mJumpingWall && collisionFlags == CollisionFlags.Sides) { //check if we are going up if(!wallStickDownOnly || localVelocity.y <= 0.0f) { Vector3 up = dirHolder.up; if(collisionFlags == CollisionFlags.Sides) { for(int i = 0; i < mCollCount; i++) { CollideInfo inf = mColls[i]; if(inf.flag == CollisionFlags.Sides && (wallStickInvalidMask == 0 || ((1<<inf.collider.gameObject.layer) & wallStickInvalidMask) == 0)) { float a = Vector3.Angle(up, inf.normal); if(a >= 90.0f - wallStickAngleOfs && a <= 90.0f + wallStickAngleOfs) { //wallStickForce mWallStickCollInfo = inf; mWallStickSide = M8.MathUtil.CheckSide(mWallStickCollInfo.normal, dirHolder.up); mWallSticking = true; break; } } } } } if(mWallSticking) { if(wallStickPush) { if(CheckWallStickIn(moveSide)) { if(!mWallStickWaitInput) { //cancel horizontal movement Vector3 newVel = localVelocity; newVel.x = 0.0f; //reduce downward speed if(newVel.y < -wallStickDownSpeedCap) newVel.y = -wallStickDownSpeedCap; rigidbody.velocity = dirHolder.rotation * newVel; mWallStickLastTime = Time.fixedTime; mWallStickWaitInput = true; } mWallStickLastInputTime = Time.fixedTime; } else { bool wallStickExpired = Time.fixedTime - mWallStickLastInputTime > wallStickDelay; if(wallStickExpired) { mWallStickWaitInput = false; mWallSticking = false; } } } else { bool wallStickExpired = Time.fixedTime - mWallStickLastTime > wallStickDelay; //see if we are moving away if((wallStickExpired && CheckWallStickMoveAway(moveSide))) { if(!mWallStickWaitInput) { mWallSticking = false; } } else if(!lastWallStick) { mWallStickWaitInput = true; mWallStickLastTime = Time.fixedTime; //cancel horizontal movement Vector3 newVel = localVelocity; newVel.x = 0.0f; //reduce downward speed if(newVel.y < -wallStickDownSpeedCap) newVel.y = -wallStickDownSpeedCap; rigidbody.velocity = dirHolder.rotation * newVel; } } } if(mWallSticking != lastWallStick) { if(mWallSticking) { mJump = false; lockDrag = false; } else { if(wallStickPush) mWallStickWaitInput = false; } } } if(mLastGround != isGrounded) { if(!mLastGround) { //Debug.Log("landed"); //mJump = false; //mJumpingWall = false; mJumpCounter = 0; if(localVelocity.y <= 0.0f) { if(landCallback != null) landCallback(this); } } else { //falling down? /*if(mJumpCounter <= 0) mJumpCounter = 1;*/ mJumpLastTime = Time.fixedTime; mLastGroundTime = Time.fixedTime; } mLastGround = isGrounded; } }
protected override void RefreshCollInfo() { base.RefreshCollInfo(); //bool isGroundColl = (mCollFlags & CollisionFlags.Below) != 0; if (mIsOnPlatform) { mCollFlags |= CollisionFlags.Below; mCollGroundLayerMask |= mIsOnPlatformLayerMask; } bool lastWallStick = mWallSticking; mWallSticking = false; if (isSlopSlide) { //Debug.Log("sliding"); mLastGround = false; mJumpCounter = jumpCounter; } //refresh wallstick else if (wallStick && !mJumpingWall && collisionFlags == CollisionFlags.Sides) { Vector3 up = dirHolder.up; if (collisionFlags == CollisionFlags.Sides) { for (int i = 0; i < mCollCount; i++) { CollideInfo inf = mColls[i]; if (inf.flag == CollisionFlags.Sides) { float a = Vector3.Angle(up, inf.normal); if (a >= 90.0f - wallStickAngleOfs && a <= 90.0f + wallStickAngleOfs) { //wallStickForce mWallStickCollInfo = inf; mWallStickSide = M8.MathUtil.CheckSide(mWallStickCollInfo.normal, dirHolder.up); mWallSticking = true; mJump = false; lockDrag = false; break; } } } } if (mWallSticking) { bool wallStickExpired = Time.fixedTime - mWallStickLastTime > wallStickDelay; //see if we are moving away if (wallStickExpired && CheckWallStickMoveAway(moveSide)) { if (!mWallStickWaitInput) { mWallSticking = false; } } else if (!lastWallStick) { mWallStickWaitInput = true; mWallStickLastTime = Time.fixedTime; //cancel horizontal movement Vector3 newVel = localVelocity; newVel.x = 0.0f; //reduce downward speed if (newVel.y < -wallStickDownSpeedCap) { newVel.y = -wallStickDownSpeedCap; } rigidbody.velocity = dirHolder.rotation * newVel; } } } if (mLastGround != isGrounded) { if (!mLastGround) { //Debug.Log("landed"); //mJump = false; //mJumpingWall = false; mJumpCounter = 0; if (landCallback != null) { landCallback(this); } } else { //falling down? /*if(mJumpCounter <= 0) * mJumpCounter = 1;*/ mJumpLastTime = Time.fixedTime; } mLastGround = isGrounded; } }