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

Detecting where knife(object) is being hit and add score according to that.....

Discussion in 'General Discussion' started by hamza37, Mar 15, 2020.

  1. hamza37

    hamza37

    Joined:
    Feb 5, 2017
    Posts:
    10
    I have been working on the 2d game where player has to hit the knife on the target and and if knife hit on exact center he will get bonus points and get lower if hit else where.........so how would i achieve that any suggestions?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Get hit coordinates and compare them to the coordinates of the center of the target. If they're close enough to each other, then the player hit the center.
     
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    You can score rings as well by just determining the radius of the rings and apply a score of lessening value outwards by determining the distance from center coords and finding which set of radii it is between. You could score the rings from the center out as for example 100, 80, 60, 40, 20 to even it out or 100, 50, 25, 12, 5 for a different scoring gradient.
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,084
    Yep, like ippdev says, this is basically a distance check from center.
     
  5. hamza37

    hamza37

    Joined:
    Feb 5, 2017
    Posts:
    10
    thankyou @ippdev and @neginfinity for the suggestions......i will try your solutions....right now i have applied colliders solution but its not working properly....because my targets are on left and right side of the 2d plane
     
  6. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    What do you mean "not working properly"? Does the knife nor stick in? If so you have to fake that. Other than that you have a target. Create collider to match target geometry. Throw knife and get the contact point position and compare to the center position of the target hit.
     
    angrypenguin likes this.