Playing with Collisions and Triggers
More about OnCollisionEnter and OnTriggerEnter
Collisions
How to use collisions? Well…
For this little testing, you need colliders and rigidbodies! :)
I recommend you try out how everything works and just play with this and have fun! :D
In this example, I used OnCollisionEnter to see if the game object we collisions with was tagged as a player. And when that happened, our main cubes speed was set to 0f.
Rigidbodies can be used to add mass & drag to an object. You can also choose if it uses gravity or is it just kinematic.
The more you have drag, the slower it will drop down.
And the more you have mass, the faster it drops down. But… if the cube would be on the ground and something would collide with it. The cube wouldn’t move much because of the mass.
Triggers
Triggers are good to play a certain music track, change color, move an object up or anywhere you want. Triggers are used on soft collisions as I described before.
Making the cube go up I used transform.Translate and of course when the player triggers this again the cube will go up again by 2f. :D
But which one to choose? And why?
If you want soft collisions as I described before with the color change or music… Triggers are good for that.
But if you want hard collisions like crashes or falling from the sky onto the ground, then you should use collision.
That’s it for now…
Thank you for reading! Much love & see you in the next one! :)