public void hitboxUpdate() { if (_state == ColliderState.Closed) { return; } Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, hitboxSize, 0, mask); for (int i = 0; i < colliders.Length; i++) { Collider2D aCollider = colliders[i]; _responder?.collisionedWith(aCollider); } _state = colliders.Length > 0 ? ColliderState.Colliding : ColliderState.Open; stopCheckingCollision(); }
public void hitboxUpdate() { // if (state == ColliderState.Closed) { return; } Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position + offset, halfExtent * 2, transform.rotation.y, layerMask); for (int i = 0; i < colliders.Length; i++) { Collider2D aCollider = colliders[i]; // Make sure you are not hitting yourself if (aCollider.transform.parent != transform.parent) { responder?.collisionedWith(aCollider); } } state = colliders.Length > 0 ? ColliderState.Colliding : ColliderState.Open; }
private void Update() { if (_state == ColliderState.Closed) { endHitbox(); return; } playerOrientation = transform.GetComponent <PlayerManager>().getPlayerOrientation(); //Update Hitbox location and orientation to follow player hitboxPosition = transform.position + Quaternion.Euler(0, (float)playerOrientation, 0) * hitboxPosOffset[hitboxIndex]; hitboxRotation = Quaternion.Euler(0, (float)playerOrientation, 0) * hitboxRotOffset[hitboxIndex]; hitboxSize = hitboxSizeList[hitboxIndex]; //Decrement move up-time timer hitboxTimer[hitboxIndex] = hitboxTimer[hitboxIndex] - Time.deltaTime; //Check for collision Collider[] colliders = Physics.OverlapBox(hitboxPosition, hitboxSize, hitboxRotation, LayerMask.GetMask("Hurtbox")); if (colliders.Length == 0) { _state = ColliderState.Open; } foreach (Collider c in colliders) { //Do not count collisions with yourself if (c.transform.root == transform) { continue; } //FIXME: for now, just apply knock back, will compartmentalize this later if (_state == ColliderState.Colliding) { _state = ColliderState.Inactive; } else { _state = ColliderState.Colliding; } if (_responder != null && _state == ColliderState.Colliding) { _responder.collisionedWith(c, moveName); } //FIXME: This is what you're going to need to change if you want 1 hitbox to affect more than one person // c.transform.root.GetComponent<Player>().hitStunTimer = 1f; // c.transform.root.GetComponent<Rigidbody>().AddForce(new Vector3(30, 30, 0)); } //Check if move is finished if (hitboxTimer[hitboxIndex] <= 0f) { //Out of hitboxes, this move is done if (hitboxIndex >= hitboxNumStates - 1) { endHitbox(); } //Still more hitboxes, make sure each hitbox hits only once else { hitboxIndex++; if (_state == ColliderState.Inactive) { _state = ColliderState.Open; } } } }