How to detect collision position and velocity?

Hi,
I’m trying to build a brick-breaker like game, and I handle the ball - pad collision via OnTriggerEnter(), and I want to know the x-coordinate of collision with respect to the center of paddle, to aim the ball.
And I want to get the pad’s (rigidbody) velocity when it hits the ball. In the code below, why does the pad velocity return 0 ?

function OnTriggerEnter(other:Collider)
{
    if(other.rigidbody){
    V_pad=other.rigidbody.velocity;
    //Here it returns (0,0,0) , also tried other.attachedRigidbody
    }    

    if(other.name=="Pad"){
    rigidbody.velocity = 
Vector3(rigidbody.velocity.x, Mathf.Abs(rigidbody.velocity.y + V_pad),0); 
//this part executes but with V_pad.y=0
    }
}

Thanks for any help!

Hi,

i have tried to make a brick breaker game before and i had trouble with the pad and bouncing as well. What i did, i had 3 smaller pads and put then into and empty game object and then put the movement script on the empty so they would move… i then added a bounce material onto the ball… (it was my own because the unity one dosent give you a perfect bounce. I put the dynamic friction to 0, static friction to 0. bounciness to 1, friction combine to minimum and bounce combine to maximum… everything else was set to 0). i left the middle paddle empty of scripts but i added a box collider. i did the same with the other 2 but i added a script to make it bouce away from the pad with the OnCollisionEnter function and i added a Ball tag to the ball.

probably not what your looking for but this is how i did it

Hi there,

I was just searching the internet for something for my own brick-breaker game and I saw your question. I remember that back when I was starting my project, this was the first big challange and I finally found it. :slight_smile:

Here is the code in CSHARP but you can try it in javascript also:

void OnCollisionEnter (Collision col) {
	foreach (ContactPoint contact in col.contacts) {
		if(contact.thisCollider == collider) {
			float english = contact.point.x - transform.position.x;
			contact.otherCollider.rigidbody.AddForce(300f * english, 0, 0);
		}
	}
}

You may need to tweak the code above and play around with the numbers but it should work if your ball is physics powered (which I guess it is).

I hope that I am not late with my solution and I can help you and other people with this question.