Search Unity

2D Break Ball Paddle (Curve machenism)

Discussion in '2D' started by RajRajRaj, Oct 29, 2015.

  1. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    Hye there
    Code (CSharp):
    1.          void OnCollisionEnter2d(Collision2D other){
    2.             foreach (ContactPoint2D contact in other.contacts) {
    3.                 if(contact.collider == GetComponent<Collider2D>()){
    4.                     float english = contact.point.x - transform.position.x;
    5.                     contact.otherCollider.attachedRigidbody.AddForce(new Vector2(200f * english,0f));
    6.                 }
    7.             }
    8.         }
    9.  
    in 2d breakout game(break ball game)
    i m trying to add mechanism in paddle like when ball hits left sides of the paddle it bounce ball in the direction which it came from and same as right i m using that script....

    what i m doing wrong if u can than tell me else no problem because i know u guys r very busy :)
    thats a humble request


    @Adam Buckner
    @Matthew Schell
     
    Last edited: Oct 30, 2015
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Funny, those tags look correct. @Matthew Schell should know more than I do.
     
  3. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    ???


    whats about my paddle (Game) problem?
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    RajRajRaj likes this.
  5. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Sorry I'm not able to help with this, I am happy to answer questions directly related to the original tutorial but as far as adding new things or converting it to 2D you'll need to find help elsewhere. If you haven't converted it to 2D (as it appears) you should be using regular collision instead of Collision2D, etc.
     
  6. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42

    ohhhh,,,,,,,

    any ways i can understand ur problem...
    thnx 4 replying and to be straight forword :)
     
  7. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    You have misspelled OnCollisionEnter2d, there should be a capital D at the end; OnCollisionEnter2D.

    I think you have too much code for what you are trying to accomplish. If you know that the ball has hit your bat, why not just compare the position of the bat and the ball. Assuming you have the pivots at the center of each object; if the transform.position.y of the ball is less than the transform.position.y of the bat then the ball is to the left of the bat and vice versa. The difference in y position will tell you how far from the bat's center the ball is, which you can use to adjust the angle of the ball.