2D Break Ball Paddle (Curve machenism)

Hye there

         void OnCollisionEnter2d(Collision2D other){
            foreach (ContactPoint2D contact in other.contacts) {
                if(contact.collider == GetComponent<Collider2D>()){
                    float english = contact.point.x - transform.position.x;
                    contact.otherCollider.attachedRigidbody.AddForce(new Vector2(200f * english,0f));
                }
            }
        }

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 :slight_smile:
thats a humble request

@Adam-Buckner_1
@Matthew-Schell

Funny, those tags look correct. @Matthew-Schell should know more than I do.

???

whats about my paddle (Game) problem?

1 Like

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.

ohhhh,

any ways i can understand ur problem…
thnx 4 replying and to be straight forword :slight_smile:

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.

3 Likes