Hey,
I was wondering if someone could help me with my pong game.
I want to get the ball to ricochet depending on where it hits the racket.
I have searched the internet but I could not find any good scripts.
Thanks.
Thats what I want, I will try to code something but im still in the process of learning so i may need some help. ![]()
Looks like i’m going to need some help please.
I just dont quite understand.
I want my Pong “Ball” to ricochet in a certain direction depending on where it hits the “Racket”.
Can anyone help me?
Is it really that hard, Vector3.Reflect, on collision with the paddle you just get the last know direction the ball was moving in, the surface normal of the face that got collided with. Plug that into Vector3.Reflect and it will return you the direction the ball should be going in after the bounce.
It is for me.
Sorry if I seem dumb but i’m still learning (Thats what everyone says, I know)
Unity - Scripting API: ContactPoint.normal get the normal of the collision
and assuming your ball or whatever has/is using a rigidbody:
void OnCollisionEnter(Collision other)
{
//also probably put some sort of tag check or something to make sure we hit the paddle or whatever
rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, other.contacts[0].normal);
}