game object when a bullet (a game object that contains the tag of 'bullet') collides with them (which is very well optimised due to only being a few lines long): "
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag=="bullet")
Destroy(gameObject);
}
Using the Unity editor, you can apply Box Colliders (for 2d or 3d games) right in the inspector view, and then scale/ adjust the size and placement accordingly to match the object's general shape. You can normally only have one box trigger at a time, by adding it as a component for the character, so instead making the main character a parent class, then creating various other blank game objects underneath it with their own box triggers can create a much more intricate form of collision detection and not have the character have a simple box around them with dodgy collision from certain angles. Here's an example image (screencapped by me) for a main character below (the green boxes represent various box colliders attached to one object, which help shape the general dimensions of the bird and how a simple box wouldn't be able to properly fill the whole shape):
Raytracing is a more advanced version of collision detection that doesn't use boxes, but draws invisible lines instead, which I explained in more detail in an earlier blog post!
No comments:
Post a Comment