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

Detect a hit on the left or right of an object

Discussion in 'Scripting' started by Chris Aoki, Mar 13, 2013.

  1. Chris Aoki

    Chris Aoki

    Joined:
    Jan 15, 2012
    Posts:
    200
    Hello everyone,

    I am attempting to make a breakout style game, I've just run into one little problem. I am trying to determine if the ball has hit a brick on the left or right side. Anyone have any ideas?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    take a dot product of the normalized vector (contactPoint.position-brick.position) with your right vector. if the result is positive, it's on the right, if negative, on the left