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. Dismiss Notice

Idea about punch position C#

Discussion in 'Scripting' started by Dekata, Sep 15, 2016.

  1. Dekata

    Dekata

    Joined:
    May 20, 2016
    Posts:
    47
    Minasan, i try to make a 2.5D fighting game, and need your advices about how to know punch position and lock the player arm at this place(not allow player punch throw Enemy).
    At the begin, i try to add a sphere collider and use OnTriggerEnter to add damage to Enemy, then use Physics.Spherecast
    Code (CSharp):
    1.  Vector3 dir = new Vector3(1, 0, 0);
    2.         // Debug.draw(transform.position, dir);
    3.         if (Physics.SphereCast(transform.position - dir,0.23f, dir, out hit, 1, hitlayer))
    4.         {
    5.             Debug.Log("hit Player");
    6.  
    7.         }
    to know the point of hit , but it seem not work. thanks guys alot
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    By 2.5D do you mean its an isometric view like diablo, or 2D gameplay using 3D graphics?
    What do you mean point of hit, the precise location on the enemy the player's punch landed on?
     
    Dekata likes this.
  3. Dekata

    Dekata

    Joined:
    May 20, 2016
    Posts:
    47
    like Mortal Kombat , my character have a long arm like Hulk, so if he punch on bad ass face, his hand go throw enemy body and this shouldn't be so I think i can use Spherecast to get the point that punch collider with enemy body but it not work
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Can you go through the details of what you are trying to achieve again (preferably without relying on references to other games/characters that we might not have played :p).

    How are you performing the punch? animation?
     
  5. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    I ask about precision since it will affect how collision is done. Since it is a fighting game, I give you this video as a reference.

    Fighting games are very frame dependent, which makes the job of collision rather tricky. Do you depend on animation or manually set collisions? Both approaches and anything in between tiptoe between development freedom and precision.

    On another note, despite street fighter using 3D graphics, it still uses 2D collisions.

    On the tech side of things, Unity's collision system does not account intersections of objects which spawn within another. This be because collisionEnter or triggerEnter, requires the objects to move into each other for the collision to register.

    Ive overcome that problem by having the object scale to 1 at an infinitely fast rate when they spawn, thereby making the collision seem instantaneous, while allowing Unity to detect the collision. It cannot be completely within another object though, that probably still will not register as a collision.
     
    Dekata likes this.
  6. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Bro...never played street fighter or mortal combat? Give me your parents phone number immediately. I'm going to have a stern talking.
     
  7. Dekata

    Dekata

    Joined:
    May 20, 2016
    Posts:
    47
    @Laperen I use animation, so the mechaniz only work with 2d can we use ragdoll
    PS: confuse about scale, when i add scale.z= -1 the character will change the facing direction but if i add animation, all of his body underground, only charactercontroller is up, why that is?
     
    Last edited: Sep 16, 2016