private void OnEnable() { state = State.NEUTRAL; speed = speedNeutral; angleIndex = Random.Range(0, 4) * 2 + 1; angle = Angles.GetAngle(angleIndex); SetPSysColorLifetime(ps, colorsNeutral); coll.enabled = true; }
private void FixedUpdate() { Velocity = Vector2.zero; if (inputMove >= 0) { walkDir = inputMove; walkAngle = Angles.GetAngle(inputMove); inputMove = -1; Velocity = Angles.GetDirection(walkAngle) * moveSpeed; swordAnchor.rotation = Quaternion.Euler(0f, 0f, Mathf.Rad2Deg * walkAngle); } rb.MovePosition(rb.position + (Velocity + (hitNormal * bounceForce)) * Time.fixedDeltaTime); hitNormal *= forceFalloff.Evaluate(Mathf.Clamp01((Time.time - hitTime) / 1f)); }
public void Hit(int hitAngleIndex) { if (IsExploding) { return; } onHit.Invoke(gameObject); if (IsCharged) { StartCoroutine(Explosion(4)); } int angleDiff = 8 - angleIndex; int hitAngleRelative = (hitAngleIndex + angleDiff) % 8; // if (hitAngleRelative == 0) { // Debug.Log("from behind"); // } if (hitAngleRelative == 4) { angleIndex += 4; } if (hitAngleRelative > 0 && hitAngleRelative < 4) { angleIndex += 2; } if (hitAngleRelative > 4 && hitAngleRelative < 8) { angleIndex -= 2; } state = State.CHARGED; SetPSysColorLifetime(ps, colorsCharged); speed = speedCharged; angleIndex %= 8; if (angleIndex < 0) { angleIndex = 8 + angleIndex; } angle = Angles.GetAngle(angleIndex); }
private void FixedUpdate() { rb.MovePosition(rb.position + GetVelocity() * Time.fixedDeltaTime); hitNormal = Vector2.zero; for (int i = 0; i < raycastDirs.Length; ++i) { hitNormal += Raycast(raycastDirs[i]); } if (hitNormal == Vector2.zero) { return; } angleIndex = DeflectAngleIndex(angleIndex, hitNormal, GetVelocity().normalized); angle = Angles.GetAngle(angleIndex); rb.MovePosition(rb.position + GetVelocity() * Time.fixedDeltaTime * 2f); }