- Home /
[Top Down Shooter] Make bullets pass through some gameobjects
Hi,
Thanks for reading. My game has two factions: (player + allies) & enemies. I would like to make it so bullets which hit members of the same faction pass through them. At present, if a bullet hits a member of the same faction, it 'curls' around it. I tried hiding the bullet and its trail renderer, but the problem is more that the bullets go off course than appearance of it curling around the gameobject.
Bullets have rigidbodies, as do the members of all factions. If you need more info, please let me know!
// If the bullet collides with an enemy
if(Other.gameObject.tag == "Enemy")
{
// Get the script of the hit enemy
EnemyScript es = (EnemyScript) Other.gameObject.GetComponent("EnemyScript");
// Damage enemy
}
// If the object is not an enemy, hide the bullet
else if(Other.gameObject.tag == "Ally")
{
HideBullet();
}
It's extra work but make separate bullets for each faction, then use Layer-Based collision detection. Have the player bullet layer ignore the player object layer, and the same for enemy bullets : http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
Thanks for answers. Any reason why I might pick one over the other? I won't be saving the state in the scene the bullets are present in (noticed that the was some issue with this)
Tried out ignore collision. Works perfectly. Thanks. Will try out making separate bullets if I run into trouble down the line.
EDIT: Tested out both methods. Ignore collision works most, but not all of the time. $$anonymous$$ay be down to error on my behalf. Layer based seems to work all the time, and cuts down the complexity of the bullet script. Seems the better option in this case. Appreciate the help guys!
Answer by darthbator · Oct 10, 2013 at 06:06 PM
Read this
http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
You'll want to put separate factions on separate collision layers. This is the easiest way to achieve this manner of things IMO.
Your answer
Follow this Question
Related Questions
Writing weapon imprecision 1 Answer
2D Aiming in Physics Based Racer 0 Answers
Jittery Movement (2D) 4 Answers
How to make a simple line of sight in a 2D top down shooter. 3 Answers