Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Extra Hit Checking

Discussion in 'Scripting' started by nickavv, Aug 22, 2007.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I want to make it so that if you press the jump button just before landing on an enemy's head it will do extra damage, so I figure that you should have to be: Pressing the Key (not holding it), a little way above the enemy, and moving downwards. This block of code should do it I would think, but it still turns on even when I'm moving upwards. I don't think I'm using rigidbody.velocity correctly.. Any thoughts?

    Code (csharp):
    1. if (Input.GetButtonDown("Jump")  hero.transform.position.y <= transform.position.y + 1.2  hero.rigidbody.velocity.y < 0) {
    2.         actionCom = true;
    3.     }
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Nothing in that code looks wrong to me, so either all of those conditions are being met or actionCom is being set to true elsewhere.
     
  3. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    I would put in a Debug.Log() within the conditional to see what velocity.y was as well as the to position.y was for each transform.
     
  4. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    You set actionCom to true if <your condition>... but when do you set it to false?
    Maybe you should do
    Code (csharp):
    1. actionCom = (Input.GetButtonDown("Jump")  hero.transform.position.y <= transform.position.y + 1.2  hero.rigidbody.velocity.y < 0);