I want to get an object to bounce of walls etc, where the bouncing angle is mirrored in the normal of the plane where the bouncing object hit the static object (I hope I got that right!). I know the math, but I don’t know how to find the normal. How would I go about it using Unity cubes? Meshes created in a 3D program?
ContactPoint.normal
–Eric
if you use collisions the collision object you get will contain the normal, if you use raycasts, the raycasthit contains it ![]()
Thanks for the quick replies. The moving object is non-kinematic so I am currently using OnTriggerEnter. In order to use the ContactPoint.normal I have to use OnCollisionEnter, forcing me to put a rigidbody on all static objects, right?
I don’t think raycasts is a good option in this case since I’d have to do one in the current direction the object is moving, as well as another one either up, down, right or left depending on the current movement direction of the object. So have to make tests to find out which direction to fire that second raycast and then fire two of them.
What kind of disadvantages to using rigidbodies on everything vs not using any? The objects get bigger. What else?
Static objects should never use a rigidbody. It doesn’t affect collisions.
–Eric
I mistyped. I meant that the moving object is kinematic, not non-kinematic.
Eric, I’m not sure I follow? In order to use the ContactPoint.normal I will have to use the OnEnterCollision method, no? And to be able to use that method at least one of the two objects colliding have to be a non-kinematic object. Since the moving object is kinematic. and since “Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.”, I will have to attach rigidbodies to all static objects, won’t I?
Since I don’t want the static objects to move though, it would be better to make them be kinematic and the moving object non-kinematic. I think it will work out well that way too. I hope.
Yep.
What you should do is have the moving object be non-kinematic.
It would be even better to not have rigidbodies on static objects at all.
–Eric
Fully agree with Eric
Add rigidbodies to the objects that move, cause only they can enter a collision anyway and only they need to know about the normal as only they are moving away basing on the normal or some side effect of the collision again.
If you want to do something like a bumper where the surface bounces you away, you would then make the component on the object send a message to the object it collided with which doesn’t require a receiver or alternatively look for the presence of a specific component and call a function on that if present.
thats far less performance eating.
Also making an object non movable physically wise means that you really can’t move it. if you still do it all collisions triggered while moving become a hit and miss game as your object is physically not moving but teleporting so you can jump through stuff or miss collision events at worst.
Yah. It all makes sense now. Was dead tired last night and stuck in the mindset of having to have rigidbodies on everything since the moving object was kinematic. Switching it around and making the movig object non-kinematic means the “requirements” are fullfilled even if there are no rigidbodies on the static stuff. All good now, thanks!