private void DeactivateThrow() { m_currentThrowState = ThrowState.Inactive; m_pm.DisableUserInput(false); Time.timeScale = m_normalTimeScale; Time.fixedDeltaTime = Time.timeScale * 0.02f; }
private void OnTriggerExit2D(Collider2D collision) { GameObject collidingGameObject = collision.gameObject; if (retrievableObjectsHeld.Contains(collidingGameObject.name)) { return; } bool isTrash = collidingGameObject.CompareTag("retrievable"); bool isThrowTrigger = collidingGameObject.CompareTag("throwArea"); bool isTarget = collidingGameObject.CompareTag("target"); if (isTrash) { inRangeRetrievableObjects.Remove(collidingGameObject.name); } else if (isThrowTrigger) { throwState = ThrowState.CannotThrow; } else if (isTarget) { inRangeTargets.Remove(collidingGameObject.name); } }
void InitFSM() { IdleState idleState = new IdleState(gameObject); RunState runState = new RunState(gameObject); ThrowState throwState = new ThrowState(gameObject); DeadState deadState = new DeadState(gameObject); // 注册切换条件 对应的 状态 idleState.AddTransition(FSMTransition.IdleToRun, FSMStateId.Run); runState.AddTransition(FSMTransition.RunToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToThrow, FSMStateId.Throw); runState.AddTransition(FSMTransition.RunToThrow, FSMStateId.Throw); throwState.AddTransition(FSMTransition.ThrowToIdle, FSMStateId.Idle); idleState.AddTransition(FSMTransition.IdleToDead, FSMStateId.Dead); runState.AddTransition(FSMTransition.RunToDead, FSMStateId.Dead); throwState.AddTransition(FSMTransition.ThrowToDead, FSMStateId.Dead); system.AddState(idleState); system.AddState(runState); system.AddState(throwState); system.AddState(deadState); system.Start(FSMStateId.Idle); }
private void OnTriggerEnter2D(Collider2D collision) { GameObject collidingGameObject = collision.gameObject; if (retrievableObjectsHeld.Contains(collidingGameObject.name)) { return; } bool isTrash = collidingGameObject.CompareTag("retrievable"); bool isTarget = collidingGameObject.CompareTag("target"); bool isThrowTrigger = collidingGameObject.CompareTag("throwArea"); if (isTrash) { inRangeRetrievableObjects.Add(collidingGameObject.name); } else if (isThrowTrigger) { if (collidingGameObject.name == "LeftTrigger") { throwState = ThrowState.CanThrowLeft; } else { throwState = ThrowState.CanThrowRight; } } else if (isTarget) { inRangeTargets.Add(collidingGameObject.name); } }
private void FixedUpdate() { switch (_state) { case ThrowState.None: return; case ThrowState.Grabbed: _accelerationValues.Enqueue(transform.position); if (_accelerationValues.Count > _queueLength) { _accelerationValues.Dequeue(); } break; case ThrowState.Released: _state = ThrowState.None; var values = _accelerationValues.ToArray(); if (values.Length > 0) { var currentAcceleration = values[_queueLength - 1] - values[0]; _rigidbody.AddForce(currentAcceleration * _initialSpeedMultiplier, ForceMode.Impulse); } _accelerationValues.Clear(); break; } }
private void AimThrow() { m_currentThrowState = ThrowState.Aiming; m_pm.DisableUserInput(true); m_pm.externalVelocity = Physics2D.gravity * 0.5f; //m_pm.momentum = MomentumVelocity; if (m_slowTimeWhileAiming) { SlowTime(); } m_throwVelocity = GetAimDirection(m_contDirWithoutDeadzone); //if (m_usingController) //{ // m_throwVelocity = GetAimDirection(m_contDirWithoutDeadzone); //} //else //{ // m_throwVelocity = GetAimDirection(m_mouseDirection); //wird das funktionieren? // wenn ja wie gut? --> funktioniert ganz ok --> bei maus wird immer mit maximaler kraft geworfen //} if (m_input.player.GetButtonDown(m_input.jumpButton)) { m_pickedUpObject.GetComponent <ThrowableObject>().Drop(); m_pickedUpObject = null; DeactivateThrow(); GetComponent <VisualizeTrajectory>().RemoveVisualDots(); } }
private void OnMouseDown() { if (_state == ThrowState.WAITING) { _offset = transform.position - UnityEngine.Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -UnityEngine.Camera.main.transform.position.z)); _state = ThrowState.IN_HAND; } }
void Start() { throwState = ThrowState.None; ikController = GetComponent <IKController>(); ikCatchController = GetComponent <IKCatchController>(); ikDeflectController = GetComponent <IKDeflectController>(); animator = GetComponent <Animator>(); }
//Coroutine to shoot projectile IEnumerator Shoot() { //Stuff for bouncing weapons if (currWeapon.name == "Rock") { projectile.GetComponent <Projectile>().rock = true; } if (currWeapon.name == "Brick") { projectile.GetComponent <Projectile>().brick = true; } //Throwing sounds throwingSound.Play(); wait = true; //Find mouse position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //calculate direction vector for weapon to aim point Vector3 direction = (ray.direction * range + ray.origin) - projectile.transform.position; //Turn rigidbody back on and throw the projectile projectile.GetComponent <Rigidbody> ().isKinematic = false; projectile.rigidbody.AddForce(direction.normalized * range, ForceMode.Impulse); projectile.GetComponent <Projectile> ().thrown = true; if (currWeapon.stick) { projectile.GetComponent <Projectile> ().sticky = true; } projectile.transform.parent = null; projectile.GetComponent <Projectile>().dmgModifier = currWeapon.dmg; loaded = false; shooting = false; //wait for cooldown yield return(new WaitForSeconds(currWeapon.coolDown)); //subtract from weapon quantity and load next weapon currWeapon.SubtractQuantity(); //Debug.Log ("switching: " + switching); if (!switching) { LoadWeapon(); } wait = false; loaded = true; state = ThrowState.STATE_UP; }
private ThrowState() { if (_instance != null) { return; } _instance = this; }
public void ReleaseBall() { // Ran as an animation event // Apply throw force to the ball Quaternion towards = transform.rotation; if (target != null) { Transform rHand = animator.GetBoneTransform(HumanBodyBones.RightHand); towards = Quaternion.LookRotation(target.position - rHand.position); } Transform thrownBall = ikCatchController.caughtBall; ikCatchController.ReleaseCaughtBall(); ThrownController ballThrownController = thrownBall.gameObject.AddComponent <ThrownController>() as ThrownController; Vector3 beginningPoint = thrownBall.position; Vector3 endPoint = target.position; Vector3 direction = endPoint - beginningPoint; Vector3 tmpPoint = beginningPoint + direction * 0.9f; Vector3 controlPoint; ThrowPath throwPath = null; switch (throwPathState) { case ThrowPathState.Straight: throwPath = new StraightPath(beginningPoint, endPoint, throwSpeed); break; case ThrowPathState.CurveFromRight: controlPoint = tmpPoint + (Quaternion.AngleAxis(-90.0f, direction.normalized) * Vector3.up * 3); throwPath = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed); break; case ThrowPathState.CurveFromLeft: controlPoint = tmpPoint + (Quaternion.AngleAxis(90.0f, direction.normalized) * Vector3.up * 3); throwPath = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed); break; case ThrowPathState.CurveFromAbove: controlPoint = tmpPoint + (Quaternion.AngleAxis(0.0f, direction.normalized) * Vector3.up * 3); throwPath = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed); break; default: print("Unrecognized ThrowPathState"); break; } ballThrownController.SetThrowPath(throwPath); RemoveTarget(); throwState = ThrowState.None; }
public void OnLevelWasLoaded(int level) { if (UnLock) { return; } ThrowState state = GameObject.FindObjectOfType <ThrowState>(); if (state != null) { state.OnEnd += OnThrow; } }
private void OnMouseUp() { if (_state == ThrowState.IN_HAND) { _rb.isKinematic = false; Vector3 mov = _velocity * ConfigManager.S.Info.FireVelocity; mov.z = Mathf.Abs(_velocity.x + _velocity.y) * ConfigManager.S.Info.FireVelocity; mov += transform.forward * ConfigManager.S.Info.FireVelocity; _rb.AddForce(mov, ForceMode.Impulse); _rb.AddTorque(mov * 10f); _state = ThrowState.THROWN; } }
IEnumerator CancelShot() { shooting = false; wait = true; state = ThrowState.STATE_HOLD; range = 0; yield return(new WaitForSeconds(currWeapon.coolDown)); state = ThrowState.STATE_UP; wait = false; }
public void ReadyThrow() { // Ready for throw animation Assert.IsTrue(ikCatchController.HasCaughtBall()); ikController.setIKActive(false, enabledIKGoals); ikCatchController.setActive(false); ikDeflectController.setActive(false); // Parent ball to hand Transform rHand = animator.GetBoneTransform(HumanBodyBones.RightHand); ikCatchController.caughtBall.SetParent(rHand); ikController.setLookAt(target); throwState = ThrowState.Throwing; }
public PlayerControllerData(PlayerController player) { Player = player; PlayerRB = Player.GetComponent <Rigidbody2D>(); MainCollider = Player.GetComponent <CapsuleCollider2D>(); PlayerSpriteRenderer = Player.GetComponent <SpriteRenderer>(); PlayerCam = Camera.main; PlayerAnimator = Player.GetComponent <Animator>(); PlayerHUD = GameObject.Find("HUD_Base_Panel").GetComponent <HUD>(); PlayerBoomerang = Player.GetComponentInChildren <BoomerangObj>(); PlatformLayer = LayerMask.GetMask("World"); Idle = new IdleState(this); Movement = new MoveState(this); Jump = new JumpState(this); InAir = new InAirState(this); Aim = new AimState(this); Throw = new ThrowState(this); WallJump = new WallJumpState(this); SetState(Idle); AnimStates = new Dictionary <State, string>() { { Idle, idleAnim }, { Movement, moveAnim }, { Jump, idleAnim }, { InAir, inAirAnim }, { Aim, null }, { Throw, null }, { WallJump, onWallAnim } }; maxPlayerHealth = 100.0f; playerHealth = maxPlayerHealth; maxPlayerPotion = 50.0f; playerPotion = maxPlayerPotion; }
// Update is called once per frame void Update() { switch (state) { case ThrowState.Idle: if (Input.GetAxisRaw("Fire1") != 0) { spawnBall(); throwingArmTiltProgressionFactor = 0; currentTilt = Random.Range(-maxTiltAngle, maxTiltAngle); state = ThrowState.WindingUp; } break; case ThrowState.WindingUp: if (Input.GetAxisRaw("Fire1") == 0) { woundupEnergy = throwingArmProgressionFactor; state = ThrowState.Throwing; break; } throwingArmTiltProgressionFactor = throwingArmProgressionFactor = Mathf.Clamp(throwingArmProgressionFactor + (windupSpeed / 100) * Time.deltaTime, 0, 1); break; case ThrowState.Throwing: throwingArmProgressionFactor = Mathf.Clamp(throwingArmProgressionFactor - (throwSpeed * woundupEnergy / 100) * Time.deltaTime, 0, 1); if (throwingArmProgressionFactor == 0) { releaseBall(); woundupEnergy = 0; state = ThrowState.Idle; } break; } setThrowingArmTransform(); }
private void OnGrabbed(BaseGrabbing grabbing) { _state = ThrowState.Grabbed; }
private void OnReleased(BaseGrabbing grabbing) { _state = ThrowState.Released; }
// Update is called once per frame void Update() { //Switching Weapons if (Input.GetKeyDown(KeyCode.Alpha1) && currWeapon != inventory.items[0] && CheckQuantity(inventory.items[0]) && !inventory.items[0].locked) { if (switchWeapon != inventory.items[0]) { switchWeapon = inventory.items[0]; toLoad = inventory.Rock; StartCoroutine("SwitchWeapons"); } } if (Input.GetKeyDown(KeyCode.Alpha2) && currWeapon != inventory.items[1] && CheckQuantity(inventory.items[1]) && !inventory.items[1].locked) { if (switchWeapon != inventory.items[1]) { switchWeapon = inventory.items[1]; toLoad = inventory.Brick; StartCoroutine("SwitchWeapons"); } } if (Input.GetKeyDown(KeyCode.Alpha3) && currWeapon != inventory.items[2] && CheckQuantity(inventory.items[2]) && !inventory.items[2].locked) { if (switchWeapon != inventory.items[2]) { switchWeapon = inventory.items[2]; toLoad = inventory.Javelin; StartCoroutine("SwitchWeapons"); } } if (Input.GetKeyDown(KeyCode.Alpha4) && currWeapon != inventory.items[3] && CheckQuantity(inventory.items[3]) && !inventory.items[3].locked) { if (switchWeapon != inventory.items[3]) { switchWeapon = inventory.items[3]; toLoad = inventory.Discus; StartCoroutine("SwitchWeapons"); } } if (Input.GetKeyDown(KeyCode.Alpha5) && currWeapon != inventory.items[4] && CheckQuantity(inventory.items[4]) && !inventory.items[4].locked) { if (switchWeapon != inventory.items[4]) { switchWeapon = inventory.items[4]; toLoad = inventory.Shotput; StartCoroutine("SwitchWeapons"); } } //Input for rotating camera rotationX += Input.GetAxis("KeyboardRotate") * sensitivityX; rotationX = Mathf.Clamp(rotationX, minimumX, maximumX); transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); //Take input for canceling shot if (Input.GetButtonDown("Fire2") && !wait && shooting == true) { StartCoroutine("CancelShot"); } //Take input for how far to shoot projectile if (Input.GetButton("Fire1") && !wait && loaded == true) { shooting = true; switch (state) { case ThrowState.STATE_UP: range += rangeRate * Time.deltaTime; if (range >= maxRange) { range = maxRange; StartCoroutine("HoldCharge"); state = ThrowState.STATE_HOLD; } break; case ThrowState.STATE_HOLD: break; case ThrowState.STATE_DOWN: range -= (rangeRate / 2) * Time.deltaTime; if (range <= 0) { range = 0; state = ThrowState.STATE_UP; } break; } } //If shot has ended, smoothly reset power bar if (!shooting && range > 0) { range -= 400 * Time.deltaTime; } if (range < 0) { range = 0; } //Shoot projectile when player releases mouse button if (Input.GetButtonUp("Fire1") && !wait && loaded == true) { StopCoroutine("HoldCharge"); state = ThrowState.STATE_HOLD; StartCoroutine("Shoot"); } //change powerbar value powerBar.value = range / maxRange; PowerImage.fillAmount = range / maxRange; //put powerImage on mouse position PowerImage.transform.position = Input.mousePosition + new Vector3(13, -13, 0); // + new Vector3(16,-16,0); Camera.main.fieldOfView = Mathf.Lerp(maxFOV, minFOV, powerBar.value); ////Have projectile facing mouse position while not thrown if (loaded && projectile != null) { //Find mouse position and set lookPoint Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 lookPoint; if (range > 5) { lookPoint = ray.origin + (ray.direction * range); } else { lookPoint = ray.origin + (ray.direction * 5); } Debug.DrawRay(ray.origin, ray.direction, Color.green, 1); projectile.transform.LookAt(lookPoint); } }
public void StartAim() { SetTarget(GetInitialTarget(mainCamera.position, mainCamera.forward)); throwState = ThrowState.Aiming; }
public NormalState(Lakitu lakitu, Sprite standardSprite, Sprite throwSprite) { this.lakitu = lakitu; sprite = standardSprite; throwState = new ThrowState(lakitu, throwSprite, this); }
IEnumerator HoldCharge() { yield return(new WaitForSeconds(2f)); state = ThrowState.STATE_DOWN; }