void Awake() { if (_actor == null) { _actor = this.GetComponent <Actor>(); } _gameObject = _actor.gameObject; _actor_Data = _actor._ActorData; _transform = _actor.gameObject.transform; _headTransfrom = _actor._Bone_Head; _rigidbody = _actor.gameObject.GetComponent <Rigidbody>(); _colliderCapsule = _actor.gameObject.GetComponent <CapsuleCollider>(); _colliderTransform = _colliderCapsule.transform; _colliderYbounds = _colliderCapsule.bounds.extents.y; //bounding box distance from center to box _colliderCenter = _colliderCapsule.center; _State_MovementSpeed = State_MovementSpeed.walkSpeed; _State_Terrain = State_Terrain.ground; _State_Sliding = State_Sliding.notSliding; _State_Ragdoll = State_IsRagdoll.notRagdolled; _State_Headspace = State_Headspace.canStand; _State_LatchedSurface = State_LatchedSurface.noSurface; _remaining_Multijumps = _actor_Data._NumJumps; }
private void LatchToClimbable(bool inputCrouch) { if (!inputCrouch) { if (_State_Terrain == State_Terrain.air && _State_LatchedSurface == State_LatchedSurface.anySurface) { Debug.Log("latched to any Surface"); //kill existing velocity to prevent walljumping out of controll zeroMovement(); zeroRotation(); _State_Terrain = State_Terrain.latching; } else if (_State_Terrain == State_Terrain.air && _State_LatchedSurface == State_LatchedSurface.climbableSurface) { Debug.Log("latched to climbable Surface"); zeroMovement(); zeroRotation(); _State_Terrain = State_Terrain.climbing; } } else if (_State_Terrain == State_Terrain.climbing || _State_Terrain == State_Terrain.latching) { Debug.Log("released climb"); _State_Terrain = State_Terrain.air; } }
private void Jump(bool jump, bool JumpDown, bool crouchPressed) { { if (_State_Terrain == State_Terrain.ground) { if (crouchPressed && jump) { Debug.Log("crouch jump"); _State_Terrain = State_Terrain.air; _rigidbody.AddForce(new Vector3(0f, _actor_Data._JumpPower * 1.5f * _ConstJumpScale, 0f), ForceMode.Impulse); } else if (jump) { Debug.Log("normal jump"); _State_Terrain = State_Terrain.air; _rigidbody.AddForce(new Vector3(0f, _actor_Data._JumpPower * _ConstJumpScale, 0f), ForceMode.Impulse); } } else if (_State_Terrain == State_Terrain.latching || _State_Terrain == State_Terrain.climbing) { if (jump) { Debug.Log("walljump"); zeroMovement(); zeroRotation(); _State_Terrain = State_Terrain.air; _rigidbody.AddForce((_climbNormal + Vector3.up).normalized * _actor_Data._JumpPower * _ConstJumpScale, ForceMode.Impulse); //_rigidbody.rotation = Quaternion.LookRotation(_climbNormal * -1f); } } } }
private void CheckGround() { //check center ray first, object directly centered below us will be the _objectStandingOn //this will be the case most of the playtime, walking on plain ground //so make this check first and return if it's true Debug.DrawRay(_transform.position + _transform.transform.up * _colliderYbounds * 0.5f, -_transform.transform.up * (_colliderYbounds * 0.5f + _GroundRayLength), Color.red); if (Physics.Raycast(_transform.position + _transform.transform.up * _colliderYbounds * 0.5f, -_transform.transform.up, out _groundHitInfo, _colliderYbounds * 0.5f + _GroundRayLength)) { _State_Terrain = State_Terrain.ground; _groundNormal = _groundHitInfo.normal; _objectStandingOn = _groundHitInfo.transform.gameObject; return; } else // if the center ray did not hit anything, check the outer rays if we are standing on a ledge { for (int i = -1; i <= 1; i += 2) { for (int j = -1; j <= 1; j += 2) { Vector3 offset = new Vector3(i * _RayRadius, 0, j * _RayRadius); Debug.DrawRay(_transform.position + offset + _transform.transform.up * _colliderYbounds * 0.5f, -_transform.transform.up * (_colliderYbounds * 0.5f + _GroundRayLength), Color.red); if (Physics.Raycast(_transform.position + offset + _transform.transform.up * _colliderYbounds * 0.5f, -_transform.transform.up, out _groundHitInfo, _colliderYbounds * 0.5f + _GroundRayLength)) { _State_Terrain = State_Terrain.ground; _groundNormal = _groundHitInfo.normal; _objectStandingOn = _groundHitInfo.transform.gameObject; return; } } } } //if none of the above returned, we are in the air _State_Terrain = State_Terrain.air; _groundNormal = Vector3.up; _objectStandingOn = null; }