I’m trying to figure out how to make a bouncy ball. Currently, I’m stuck on getting a collision check to work. See below:
// On collision function
function OnCollisionEnter(Collision : Collision) {
//Bounce off ground if collision was below ball
if(Collision.whatdoIputHere < collider.center.y) {
ySpeed = 0 - ySpeed;
}
}
The whatdoIputHere in the if statement is where I am stuck. Unity’s documentation is a bit vague on how I can access the point of collision.
What I am trying to do is create several if statement checks on the collision point, and compare them to the middle of the ball. The idea is that I have xSpeed, ySpeed, and zSpeed, and I only reverse the speed if the collision that called OnCollisionEnter actually is in the correct direction.
I can get the direction, or at least I thought I could, by comparing the position of the collision and the middle of the ball(the center of the collider, in this case). But I need to figure out how to get just the x, the y, and the z of the collision point.
I keep getting errors basically along the likes of “whatever path you are using to find the data isn’t working”. I have no idea what structure the Collision object has, or why I can’t seem to find the point object/variable(which should be a vector3 type according to the documentation) inside it.
Can someone show me the right object path to get to the position of the collision point?