I´m trying to learn Raycasting collisions, but i think (i´m surely wrong) it is the same or similar to trigger (OnTriggerEnter), what is better to use?..
Thanks.
I´m trying to learn Raycasting collisions, but i think (i´m surely wrong) it is the same or similar to trigger (OnTriggerEnter), what is better to use?..
Thanks.
I would suggest you look at Will Goldstone’s excellent videos at this site. There’s one that covers raycasting.
OnTriggerEnter() is the same as OnCollisionEnter() except that you’re turning off the physics. OnTriggerEnter could be useful for detecting when a character has passed through a doorway or stepped onto a platform etc. where you don’t want the character to push or bounce off of the collider, you just want to register the hit. Either of these functions require that two colliders come in contact with each other, so you’re limited by how big a collider you place on your game object.
Raycasting allows you to interact from a distance. It casts a virtual ray in whatever direction you choose and returns info on what was hit and where. You can set it to “look” as far away as you want, 1 meter or 1000 meters or whatever you want. Think of raycasting as the eyes of your character or object. It doesn’t necessarily trigger anything. You can use raycasting to get information such as distance to an object or what object is in front of you. You can also program interaction (destroy an object, start an animation, etc) based on the info. You can cast a ray downward to get altitude of an object. It’s flexible and very useful. Hope this helps.
So, better to use OnColliderEnter…
Thanks! you helped me a lot
Hard to say without knowing what you’re trying to accomplish specifically. OnCollisionEnter() is for objects that hit each other and have physical interaction. OnTriggerEnter() is for objects that hit each other but that you don’t want to interact physically. Raycasting is for getting information from a distance by casting a virtual ray (like a laser beam) from the object. They serve different purposes, each useful in its own way.