1 (edited by MrPonton 2017-02-13 23:29:58)

Topic: Create Projectile Invulnerable Collision Box

Hey gang,

As you may or may not know I've been working on modifying the hitboxes code to suit my own greedy purposes. But don't worry, I'm still willing to share my findings and changes to those who might want it.

One collision box I needed was a collision box that ignored projectiles while also being vulnerable to physical attacks such as punches or kicks.

To perform this modification you'll need to touch three sheets: (1) GlobalInfo.cs, (2) HitBoxesScript.cs, (3) ProjectileMoveScript.cs

GlobalInfo.cs

Find the CollisionType enum and add a projectile invulnerable collider:

public enum CollisionType {
    bodyCollider,
    hitCollider,
    noCollider,
    throwCollider,
    projectileInvincibleCollider
}

Add anywhere in the sheet a new enum, and list physical and projectile. I titled it HurtBoxType:

public enum HurtBoxType {
    physical,
    projectile
}

HitBoxesScript.cs

Add a property of type to the HurtBox class and default it to a physical type:

public class HurtBox: ICloneable {
    public BodyPart bodyPart;
    public HitBoxShape shape;
    public HurtBoxType type = HurtBoxType.physical;

...

}

In the main TestCollision() method, after the foreach for hurtboxes, perform a check if the current hurt box is a projectile and the hit box is a projectile invulnerable collision box. Then have it ignore the collision:

public static Vector3[] TestCollision(HitBox[] hitBoxes, HurtBox[] hurtBoxes, HitConfirmType hitConfirmType, int mirror) {
    foreach (HitBox hitBox in hitBoxes) {

...

        foreach (HurtBox hurtBox in hurtBoxes) {
                    if (hitBox.collisionType == CollisionType.projectileInvincibleCollider && hurtBox.type == HurtBoxType.projectile) continue;

...

We're also going to want to see this new collision box in the editor window in-game and when adding it to our character. Personally, if you don't do this it will just be green like a normal hit collider which can be quite confusing, so I decided I wanted this hit box to be a simple red border. In the OnDrawGizmos() method, find the else ifs after the foreach hitBox and add an else if for the new collision type.

    void OnDrawGizmos() {

...

        foreach (HitBox hitBox in hitBoxes) {
            if (hitBox.position == null) continue;
            if (hitBox.hide) continue;
            if (hitBox.state == 1 || hitBox.collisionType == CollisionType.projectileInvincibleCollider) {
                    Gizmos.color = Color.red;
            } else if (isHit) {

...

ProjectileMoveScript.cs

Next, and finally, we need to tell any projectiles that they are in fact projectiles and should be treated equal but different to any hurtbox. Because they're special. So look inside the Start() method for the Create Hurtbox area and set the type to be projectile (remember we set it up earlier that any new HurtBox by default would be a physical type).

    // Create Hurtbox
        hurtBox = new HurtBox();
        hurtBox = data.hurtBox;
        hurtBox.type = HurtBoxType.projectile;

There you go, now you can create a Projectile Invulnerable Collision box that will take damage from any normal move's hurt boxes but avoid taking damage from any projectiles on the screen.

Share

Thumbs up +2 Thumbs down

Re: Create Projectile Invulnerable Collision Box

Fun note: You can do the same setup to make an Invincible Collider for Physical Attacks as well. This would be a collider that is only vulnerable to projectiles.

You'd basically do all the same steps. Only in HitBoxesScript.cs you'd add an additional if check after the projectileInvincibleCollider in the TestCollision() method.

public static Vector3[] TestCollision(HitBox[] hitBoxes, HurtBox[] hurtBoxes, HitConfirmType hitConfirmType, int mirror) {
    foreach (HitBox hitBox in hitBoxes) {

...

        foreach (HurtBox hurtBox in hurtBoxes) {
                    if (hitBox.collisionType == CollisionType.projectileInvincibleCollider && hurtBox.type == HurtBoxType.projectile) continue;
                    if (hitBox.collisionType == CollisionType.physicalInvincibleCollider && hurtBox.type == HurtBoxType.physical) continue;

...

Share

Thumbs up Thumbs down