x


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

more ▼

asked Aug 19 '11 at 06:02 AM

Overlord gravatar image

Overlord
484 67 78 88

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 determine 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.

Aug 19 '11 at 07:07 AM CHPedersen

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.

Aug 19 '11 at 07:11 PM Overlord

You can use tags, or the collider you hit's material, to identify it.

Aug 19 '11 at 08:42 PM stopsecret

That's what I'm trying, I'll post the finished code when I finish it (obviously).

Aug 19 '11 at 09:12 PM Overlord

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 :-)

Aug 19 '11 at 09:58 PM Bovine
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Aug 22 '11 at 05:51 PM

Overlord gravatar image

Overlord
484 67 78 88

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Aug 20 '11 at 03:17 PM

Bravini gravatar image

Bravini
1.1k 6 11 29

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x641
x181
x100
x49
x21

asked: Aug 19 '11 at 06:02 AM

Seen: 1759 times

Last Updated: Aug 22 '11 at 05:52 PM