public void TetevenWeaken() { AttackAnimation.Play("Weaken"); CurrentState = BowState.Idle; Destroy(_arrowController.gameObject); _arrowController = null; }
void Update() { if (active) { switch (currentState) { case BowState.Idle: rb.useGravity = true; rb.isKinematic = false; if (Input.GetButtonDown("AltWeapon") && altweapons.canUseAltWeapon) { GameObject altWeaponInUse = Instantiate(altweapons.altWeapons[2], altweapons.altWeaponPos, Quaternion.LookRotation(transform.forward)) as GameObject; bowObj = altWeaponInUse.transform; altweapons.canUseAltWeapon = false; altweapons.swordAndShieldShowing = false; altweapons.tpc.canMove = false; altweapons.tpc.canLookAround = false; currentState = BowState.Shoot; } break; case BowState.Shoot: rb.useGravity = false; rb.isKinematic = true; ShootArrow(); break; default: break; } } }
IEnumerator hasFired() { State = BowState.HasFired; yield return(new WaitForSeconds(CooldownAfterShot)); State = BowState.NoArrow; }
void TryChangeBowState(BowState targetBowState) { if (_changeBowStateClock.IsEnabled) { return; } if (CurrentState == State.Dying) { return; } // Armed -> Unarmed if ((CurrentBowState == BowState.Armed && targetBowState == BowState.Unarmed)) { Shoot(); } // Stand -> Armed else if (CurrentBowState == BowState.Stand && targetBowState == BowState.Armed) { Arm(); } // Unarmed -> Stand else if (CurrentBowState == BowState.Unarmed && targetBowState == BowState.Stand) { Stand(); } }
IEnumerator relaxBow() { State = BowState.Relaxing; Vector3 arrowOffset = FirePosition.localPosition - currentArrow.transform.localPosition; currentDrawLength = arrowOffset.magnitude; float speed = (currentDrawLength / relaxTime); arrowOffset.Normalize(); while (currentDrawLength > 0) { float dist = speed * Time.deltaTime; Vector3 pos = currentArrow.transform.localPosition; pos += dist * arrowOffset; currentArrow.transform.localPosition = pos; currentDrawLength -= dist; yield return(null); } yield return(new WaitForSeconds(relaxWaitTime)); State = BowState.ArrowLoaded; }
public void Shoot(Camera playerCamera) { if (CurrentState == BowState.Ready) { _arrowController.Shoot(); _arrowController = null; CurrentState = BowState.Idle; StartCoroutine(DelayShoot()); } }
public void OnFire(InputValue input) { if (bowState == BowState.READY && input.Get <float>() > 0.5f) { drawStartTime = Time.time; bowState = BowState.DRAWING; } else if (bowState == BowState.DRAWING) { bowState = BowState.LOOSING; } }
IEnumerator loadArrow() { // create arrow at fireposition as child of the bow currentArrow = GameObject.Instantiate(arrowPrefab, FirePosition.position, FirePosition.rotation, transform).GetComponent(typeof(Arrow)) as Arrow; // set state State = BowState.ArrowLoaded; // load animation (?) yield return(null); }
void ShootArrow() { bowObj.position += transform.forward * shootingSpeed; float distance = Vector3.Distance(altweapons.altWeaponPos, bowObj.position); if (distance > shootingLength) { altweapons.canUseAltWeapon = true; altweapons.swordAndShieldShowing = true; altweapons.tpc.canMove = true; altweapons.tpc.canLookAround = true; Destroy(bowObj.gameObject); currentState = BowState.Idle; } }
public void TetevenPull() { _currentPullTime = 0; var arrowGo = Instantiate(ArrowPrefab); arrowGo.transform.parent = ArrowPosition; arrowGo.transform.localPosition = Vector3.zero; arrowGo.transform.localRotation = Quaternion.identity; _arrowController = arrowGo.GetComponent <ArrowController>(); _arrowController.Init(_gameManager); AttackAnimation.Play("Pull"); CurrentState = BowState.Pull; SoundManager.PlaySFX(WorldConsts.AudioConsts.BowString, false, 0.3f); }
IEnumerator fireBow() { State = BowState.IsFiring; // shoot arrow currentArrow.transform.SetParent(null, true); GetComponent <AudioSource>().Play(); currentArrow.Shoot(getShotStrength()); // reset current arrow currentArrow = null; BowStringMidPoint.localPosition = defaultBowStringMidPoint; yield return(null); StartCoroutine(hasFired()); }
IEnumerator drawBow() { // setup in current frame State = BowState.Drawing; currentDrawTime = 0; currentDrawLength = 0; DrawSpeed = MaxDrawDistance / MinDrawTime; yield return(null); // draw loop while (currentDrawTime < MinDrawTime) { if (!isFireButtonPressed()) { currentArrow.transform.position = FirePosition.position; currentArrow.transform.rotation = FirePosition.rotation; State = BowState.ArrowLoaded; // abort yield break; } if (currentDrawLength < MaxDrawDistance) { float dist = DrawSpeed * Time.deltaTime; Vector3 pos = currentArrow.transform.localPosition; pos.z -= dist; currentArrow.transform.localPosition = pos; currentDrawLength += dist; } currentDrawTime += Time.deltaTime; yield return(null); } // advance to next state depending on whether button is pressed if (isFireButtonPressed()) { State = BowState.ReadyToFire; } else { StartCoroutine(fireBow()); } }
private void SetState(BowState newState) { switch (newState) { case BowState.IDLE: currentBowState = BowState.IDLE; OnBowReset(); break; case BowState.DRAWING: currentBowState = BowState.DRAWING; bowAnimator.SetBool("Drawing", true); break; case BowState.READY: currentBowState = BowState.READY; bowAnimator.SetBool("Ready", true); break; } }
public void BowReadyToShoot() { CurrentState = BowState.Ready; }
private void FixedUpdate() { // Grab a reference to our animator. var animator = GetComponent <Animator>(); // Cast a ray downwards to determine if we're grounded. // Use raycast instead of collider contacts because the latter doesn't work with platform effector. wasGrounded = false; if (Physics2D.Raycast(body.position, Vector2.down, groundDistance, groundMask)) { wasGrounded = true; groundTime = Time.time; // enable coyote time. } animator.SetBool("Grounded", wasGrounded); animator.SetBool("Ducking", false); // Calculate whether the player is moving or not only once. bool moveControlZero = Mathf.Approximately(0f, moveControl.magnitude); if (!moveControlZero) { // Whenever you move, reset aim control to match; always normalized. aimControl = moveControl.normalized; } switch (bowState) { case BowState.READY: target.SetActive(false); // Stop or reverse force if grounded && ready. if (wasGrounded && (moveControlZero || Vector2.Dot(moveControl, body.velocity) < 0)) { body.AddForce(-body.velocity * stopForce); } // Run when not drawing the bow. if (!moveControlZero) { body.AddForce(moveControl * moveForce); if (moveControl.y < -0.5f) { animator.SetBool("Ducking", true); } } // Jump if (wasJumping && wasGrounded && // Pressed the jump button a little too early, enable anyway. (jumpTime + jumpingLagTime > groundTime // Pressed the jump button a little too late, enable anyway. || groundTime + groundedLagTime > jumpTime) ) { body.AddForce(Vector2.up * jumpForce); wasGrounded = false; // kill ground time to prevent quick multi-jump. wasJumping = false; // needs a new press for a second jump. } break; case BowState.DRAWING: target.SetActive(true); // Rotate the aim target to match movement controls. // Also draw it closer to the explorer (and brighter) as draw time increases. var power = drawPower(); target.transform.localPosition = aimControl * 2f * (1.5f - power); target.GetComponent <SpriteRenderer>().color = Color.Lerp(new Color(.5f, .5f, .5f, .5f), Color.white, power); break; case BowState.LOOSING: // Use aimControl (already normalized) * drawPower. var b = Instantiate(projectile).GetComponent <Rigidbody2D>(); var hit = Physics2D.Raycast(body.position, aimControl, 1f, groundMask); if (hit) { // TODO: Fix to just auto-place arrow at the hit location. // For now, just don't allow shooting this close to you. } else { b.position = body.position + aimControl / 2f; b.velocity = aimControl * looseStrength * Mathf.Pow(maxStrength, drawPower()); b.SetRotation(Mathf.Atan2(aimControl.y, aimControl.x) * Mathf.Rad2Deg); } bowState = BowState.READY; target.SetActive(false); drawStartTime = Mathf.Infinity; break; } // Clamp velocity in both directions independently to avoid weird movement behavior. var v = body.velocity; v.x = Mathf.Clamp(v.x, -10f, 10f); v.y = Mathf.Clamp(v.y, -10f, 10f); animator.SetFloat("Walk Speed", Mathf.Abs(v.x)); // TODO: Rename to "VelocityX" animator.SetFloat("VelocityY", v.y); body.velocity = v; }
private static void PlayerPatch(On.Player.orig_ctor orig, Player player, AbstractCreature abstractCreature, World world) { orig(player, abstractCreature, world); int playerNumber = player.playerState.playerNumber; if (playerNumber >= totalPlayerNum) { Debug.Log("Extra slugcats detected: " + playerNumber); MoreSlugcat(playerNumber); } clubStats[playerNumber] = new ClubState { swingDelay = 0, swingTimer = 0, comboCount = 0, comboCooldown = 0, firstHit = false }; bowStats[playerNumber] = new BowState { drawTime = 0.0f, aimDir = new Vector2(0, 0), lastAimDir = bowStats[playerNumber].aimDir, controlLocked = 0, isDrawing = false, released = false }; globalStats[playerNumber] = new GlobalState { headSlot = null, bodySlot = null, accessorySlot = null, backSlot = null }; switch (player.slugcatStats.name) { case SlugcatStats.Name.White: globalStats[playerNumber].meleeSkill = 1f; globalStats[playerNumber].rangedSkill = 1f; bowStats[playerNumber].arrowLethality = 1f; break; case SlugcatStats.Name.Red: globalStats[playerNumber].meleeSkill = 1.25f; globalStats[playerNumber].rangedSkill = 0.8f; bowStats[playerNumber].arrowLethality = 1.15f; break; case SlugcatStats.Name.Yellow: globalStats[playerNumber].meleeSkill = 0.75f; globalStats[playerNumber].rangedSkill = 1.45f; bowStats[playerNumber].arrowLethality = 0.85f; break; default: globalStats[playerNumber].meleeSkill = 1f; globalStats[playerNumber].rangedSkill = 1f; bowStats[playerNumber].arrowLethality = 1f; break; } bowStats[playerNumber].drawSpeed = globalStats[playerNumber].rangedSkill * 1f; }