Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

3D Fighting Game Collision detection

Discussion in 'Physics' started by thenumberswork, Mar 23, 2016.

  1. thenumberswork

    thenumberswork

    Joined:
    Dec 24, 2014
    Posts:
    6
    Hey I'm making a 3D fighting / adventure game and I'm struggling with the best way to do collision.
    Right now I've got hitboxes on the body, hurtboxes on feet and hands. They are in separate layers so that hitboxes can only be hit by hurtboxes, but I want hurtboxes to hit anything else so that you can kick environmental objects.

    The trouble with this is that it may lead to complex collision detection for combat. I thought about using triggers for the hitboxes instead, and just detect triggers and apply damage accordingly, which would be nice for fine tuning. But in this way, a round kick will go right through the player. But maybe that's ok? I understand Street Fighter gets away with this being 2d fighter, but in a 3d game, it may be more noticeable. I guess it may be ok, if the enemy gets jolted back on trigger detection.

    Any tips or experience for this?

    1. Player can use attacks to move rigidbodies
    2. Enemy receives damage and can jolt back

    Also, I was putting rigid bodies on my players and enemies, but that sort of screws stuff up like his punches (with hands being colliders) actually shifted his body weight and threw him off to the sides. I'd like to use rigidbodies, since I'm used to making character controllers sending velocity info the the animator, and it following it thus. Also I think the player should be pushed back by bigger players. Even though I freeze rotation on my player, he will still get pushed sideways toward the ground by a punch.. Anyway to deal these issues?

    But I see how no rigidbodies may be good too, but how else will collisions be detected? moving static colliers on the hands?
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Many fighting game characters have one box or capsule collider to receive hits on the body of the character. The limbs may be ignored, depends on the game. When attacking, colliders are placed on the thrown limb/body part, and when a character's main collider touches a damaging collider, damage and impulse forces are applied to the victim. If two damage colliders ever hit each other, hit priority is calculated and damage is applied to one or both characters. Forces should still be applied to the body collider in this case.

    I recommend adding a rigidbody component to ONLY the body colliders, and leave the limbs as plain colliders. Each limb's damaging collider should only be active when that limb is part of an attack frame of an animation.

    That's my way of going about it, anyway. I hope my wording isn't confusing.
     
  3. thenumberswork

    thenumberswork

    Joined:
    Dec 24, 2014
    Posts:
    6
    Thanks good tips. I found that if I make the hand damage colliders have their own rigidbodies, but make them kinematic, it doesn't throw off the main body rigidbody. When I didn't give the damange colliders rigidbodies, the parent rigidbody would 'fill in' it's weight at the hand damage colliders, since they didn't have their own. I will contemplate turning them off and on tho.