I’m making a Space Sim and the starships/capital ships need to have shields. So what I tried to do is create a duplicate of the object make it slightly bigger, and added a transparent blue material to the shields to make it shield like, and so you can see the main ship under. The problem was, now the ship is slightly tainted blue, so I wanted a shield that was invisible, but when a laser hits it, blue particles appear in the area that it collided in. I’ve looked at the other question liked this, but It didn’t make sense to me, so I wanted a way similar to my approach. Can anyone help? Thanks in advance
2 Answers
2I'd probably do as follow : set your shield's renderer to false, give it a sphere collider and set its isTrigger to enabled. Now make a script with a function OnTriggerEnter and inside it call the function Overlap Sphere that will return all the colliders inside a given radius (your shield's radius). Get the inverse direction of the colliders and instantiate a prefab particle system containing the desired effect you want. Finally, destroy the gameobject of the collider. You will also have to filter when the overlap sphere is called and the effect to happen only with enemy bullets, but that is simply a compare tag call.
I'm not sure if this is the best way to do it, but it's actually fast enough.
Check my other question because if you’re taking the same approach as me, it answers this question. Thank you everyone who helped me. Different Explosions For Different Collisions
Actually I'm using simple colliders to see if it hits the target. And I think I answered my own question... with a question. Is there a way for me to have different type of explosions depending on what I hit? I'm working on a script for that now but, I just want to know if that is even possible.
– DayyanSissonThat's what I'm trying, I'll post the finished code when I finish it (obviously).
– DayyanSissonYou might want to consider writing a shader to draw the shield on the larger object. That's a big task and I'm no shader guru but I imagine it would be possible. I offer it as a suggestion for further research :-)
– BovineThanks Bovine, will look into that. Look at my other question which is pretty much related to this question. [Different Explosions for Different Collisions][1] [1]: http://answers.unity3d.com/questions/158402/different-explosion-for-different-collisions.html
– DayyanSissonyou could make the "shields" just not render when they are not being hit (renderer.enabled = false). then you could potentially do some cool stuff like as someone else mentioned, a shader, where that you could take the impact point and make it render a glowy effect when it gets hit.
– anon97595862