public bool ToIdle(Idle idle, Jumping jumping, Crouching crouching, Sliding sliding) { return(idle.IsIdle() && !jumping.IsJumping() && (!crouching.IsCrouching && !crouching.Rising) && !sliding.IsSliding); }
// Start is called before the first frame update void Start() { // update movespeed so equillibrium speed = expected movespeed WR_script = GetComponent <WallRunning>(); controller = GetComponent <CharacterController>(); slide_script = GetComponent <Sliding>(); velocity = new Vector3(1f, 0f, -1f); isWallRunning = false; isSliding = false; isSprinting = false; landed = false; checkpointPos = transform.position; checkpointPos.y += 1f; }
public override void InitializeFromXml(XElement e) { base.InitializeFromXml(e); Clustered = null != e.Element("cluster"); e = e.Element("logon"); if (null != e) { e = e.Element("token"); } if (null != e) { CookieName = e.Attr("cookie", CookieName); LeaseTime = e.Attr("leasetime", LeaseTime.ToString()).ToInt(); SlideTime = e.Attr("slidetime", SlideTime.ToString()).ToInt(); Sliding = e.Attr("slide", Sliding.ToString()).ToBool(); Secure = e.Attr("secure", Secure.ToString()).ToBool(); Domain = e.Attr("domain"); } }
public void Execute(Player player) { Rigidbody rb = player.GetComponent <Rigidbody>(); rb.velocity = new Vector3(player.speed, 0, 0); // Put all key checks into State functions - this gets run every frame the state is active - no need for switch if (Input.GetKeyUp(KeyCode.W)) { Standing standing = new Standing(); standing.Enter(player); } if (Input.GetKeyDown(KeyCode.Space)) { LongJump lJump = new LongJump(); lJump.Enter(player); } if (Input.GetKeyDown(KeyCode.S)) { Sliding slide = new Sliding(); slide.Enter(player); } }
// Use this for initialization void Start() { //We're supposed to be on the same gameobject as the PlayerMove, //CharacterMotor etc, so lets get them as reference! m_playerMove = GetComponent<PlayerMove>(); m_characterMotor = GetComponent<CharacterMotor>(); DoDamage = GetComponent<DealDamage>(); m_Sliding = GetComponent<Sliding>(); m_rigidBody = GetComponent<Rigidbody>(); //Did you even make a PunchBox? Or you were lazy and didn't make one? if (!PunchHitBox) { GameObject GameObjectPunchHitBox = new GameObject(); PunchHitBox = GameObjectPunchHitBox.AddComponent<BoxCollider>(); GameObjectPunchHitBox.GetComponent<Collider>().isTrigger = true; GameObjectPunchHitBox.transform.parent = transform; //Let's place it a little but farther away from us. GameObjectPunchHitBox.transform.localPosition = new Vector3(0f, 0f, 1f); //It should Ignore Raycast so let's put it on layer 2. GameObjectPunchHitBox.layer = 2; Debug.LogWarning("You were too lazy to make a PunchHitBox so I made one for you, happy?", GameObjectPunchHitBox); } //Also lets turn off our PunchHitBox, we'll only turn that on while punching //so the Grabbing script doesn't get confused with it. //PunchHitBox.enabled = false; }
private void Awake() { Player player = FindObjectOfType <Player>(); _characterController = GetComponent <CharacterController>(); _stateHelper = new PlayerMovementStateMachineHelper(); _stateMachine = new BaseStateMachine(); _playerLookVars = new PlayerLookVars(); // Hook into the BaseStateMachine OnStateChanged event _stateMachine.OnStateChanged += HandleStateChanged; // Prepare our StateParams for passing to all of our states _stateParams = new StateParams(); _stateParams.Velocity = _velocity; _stateParams.GravityOverride = defaultGravity; // Create our states Idle idle = new Idle(player); Walking walking = new Walking(player); Sprinting sprinting = new Sprinting(player); Jumping jumping = new Jumping(player); WallRunning wallRunning = new WallRunning(player, defaultGravity); Crouching crouching = new Crouching(player); Sliding sliding = new Sliding(player); // Create our state transitions // Any -> Idle _stateMachine.AddAnyTransition(idle, () => _stateHelper.ToIdle(idle, jumping, crouching, sliding)); // Any -> Jumping _stateMachine.AddAnyTransition(jumping, () => _stateHelper.ToJump(jumping, _isWallRunning, _stateParams.WallJumped)); // Idle -> Walking _stateMachine.AddTransition(idle, walking, () => walking.IsWalking()); // Walking -> Sprinting _stateMachine.AddTransition(walking, sprinting, () => PlayerInput.Instance.ShiftDown); // Sprinting -> Walking _stateMachine.AddTransition(sprinting, walking, () => !sprinting.IsStillSprinting()); // Idle -> Crouching _stateMachine.AddTransition(idle, crouching, () => PlayerInput.Instance.CrouchDown); // Walking -> Crouching _stateMachine.AddTransition(walking, crouching, () => PlayerInput.Instance.CrouchDown); // Crouching -> Walking _stateMachine.AddTransition(crouching, walking, () => _stateHelper.CrouchToWalk(crouching, walking)); // Crouching -> Sprinting _stateMachine.AddTransition(crouching, sprinting, () => _stateHelper.CrouchToSprint(crouching)); // Sprinting -> Sliding (Crouching) _stateMachine.AddTransition(sprinting, sliding, () => PlayerInput.Instance.CrouchDown); // Jumping -> Sliding _stateMachine.AddTransition(jumping, sliding, () => _stateHelper.JumpToSlide(jumping)); // Jumping -> Sprinting _stateMachine.AddTransition(jumping, sprinting, () => _stateHelper.JumpToSprint(jumping, _preserveSprint)); // Jumping -> Walking _stateMachine.AddTransition(jumping, walking, () => _stateHelper.JumpToWalk(jumping, walking, _preserveSprint)); // Jumping -> Wall Running _stateMachine.AddTransition(jumping, wallRunning, () => _isWallRunning); // Wall Running -> Sprinting _stateMachine.AddTransition(wallRunning, jumping, () => _stateHelper.WallRunToSprint(jumping, _isWallRunning, _preserveSprint)); // Wall Running -> Walking _stateMachine.AddTransition(wallRunning, jumping, () => _stateHelper.WallRunToWalk(jumping, walking, _isWallRunning)); // Default to Idle _stateParams = _stateMachine.SetState(idle, _stateParams); }