- Home /
How to Create Shields
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
What you have there, with the slightly larger model, sounds like a good approach as it is, so the way I read your problem, you're basically looking for a way to emit particles at a particular position (the impact position of the laser)? You can do that with a standard particle system where you have the emitter disabled, so it doesn't automate a constant emission of particles. I assume you're using a Raycast and a RaycastHit object to deter$$anonymous$$e whether a laserblast hit the shield or not. The RaycastHit object that gets returned contains the point of impact, in world coordinates. You can pass that point along with Color.Blue into the emitter's manual emit function, see here:
http://unity3d.com/support/documentation/ScriptReference/ParticleEmitter.Emit.html
This causes it to emit 1 particle at that exact point. For visuals, call it 10-20 times in a row with a slight, randomized offset around the laser impact point obtained from the raycast.
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.
You can use tags, or the collider you hit's material, to identify it.
That's what I'm trying, I'll post the finished code when I finish it (obviously).
You 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 :-)
Answer by DayyanSisson · Aug 22, 2011 at 05:51 PM
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
Answer by Bravini · Aug 20, 2011 at 03:17 PM
I'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.
Your answer
Follow this Question
Related Questions
How to use individual Particles as objects 1 Answer
How to make Particle System spiral/vortex 1 Answer
Particles that only show in light 2 Answers
Change Size over Lifetime for Particle System? 1 Answer
Particle System Emission Rate Scriptt 0 Answers