Hey guys,
I’m working on a mech game for my final project in school - our mech has this really cool shield, but we have a slight problem: my weapons hit it when I fire.
I’m using a mixture of Raycast weapons and Rigidbody weapons - specifically, a chaingun, a laser, and a rocket.
I know I need to use layers - I’m just having some trouble wrapping my head around it.
For my rockets, I also saw Physics.IgnoreCollision - is that a good way to go? Maybe call it on spawn, and re-enable collision after a few seconds?
If anyone has any other creative solutions, I’d also really love to hear them.
My shields have Back Face Culling off, so they’re full 3d objects - hence the hitting of the inside of the shield.
Thanks!
-Fred
In this case, using a layermask is the way to go.
First off, make sure that all your colliders are on different layers for different kinds of objects. So, have a layer for characters, a layer for enemies, a layer for enemy bullets, a layer for friendly bullets, etc.
Then, go to ‘Project Settings / Physics’ and check on the matrix which layers you want colliding with which other layers.
For your raycast lasers, it’s a bit more straightforward. If you’ve already set up all your layers (friend, enemy, etc.) you can create a ‘LayerMask’ which determines which layers the raycast can hit.
The easiest way to do this is to simply declare a public one in your class, so that it shows up in the inspector. Then, use the drop-down list to select the correct layers for your raycasts, and use that layermask in the Physics.Raycast call, using the correct overload (the one that uses a layermask).