x


Dynamic collision layers

I am writing a simple towerDefence game. There are a lot of ghost mobs and rockets, both spawning and flying around. Ghost mobs sometimes turn from spirits to fleshy and conversely.
I want rockets to move through them in spirit mode and collide when they are fleshy.

I thought it can be achieved via collision layers, but it seems that they cannot be dynamically changed through scripting.

Now i am just searching for elegant solution, that dont suggest counting every rocket and making IgnoreCollision on them for each mob.

more ▼

asked Sep 09 '12 at 01:11 PM

Toxast gravatar image

Toxast
16 1 1 2

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

2 answers: sort voted first

Layers are the best solution. You don't need to redefine the layer matrix at runtime - simply change the mob's layer from default to a specially created ghost layer depending on its state, and let the missiles in a missile layer, which doesn't collide with ghost. Supposing that you've created the ghost layer (menu Edit/Project Settings/Tags) in layer 8, control the mob's layer like this:

  if (ghostMode){ 
    gameObject.layer = 8; // move to ghost layer
  } else { 
    gameObject.layer = 0; // move to regular layer
  }

NOTE: Remember to create also the missile layer, and to configure the Collision Matrix in the Physics Manager (menu Edit/Project Settings/Physics) so that objects in ghost don't collide with missile.

more ▼

answered Sep 09 '12 at 01:39 PM

aldonaletto gravatar image

aldonaletto
41.4k 16 42 197

Thanks a lot, that is very helpful =)

Sep 10 '12 at 11:18 AM Toxast

toxa, be sure to Tick a useful answer, to keep the board tidy ! good luck

Sep 10 '12 at 12:50 PM Fattie
(comments are locked)
10|3000 characters needed characters left

I am no expert, but what about replacing them on the change event? Afaik all object can be deleted and replaced with another object, which can inherit values from the former (like position, health and so on...)

This way it would certainly be possible to have different impact or collision events.

more ▼

answered Sep 09 '12 at 02:18 PM

Headworker gravatar image

Headworker
1

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

x124

asked: Sep 09 '12 at 01:11 PM

Seen: 549 times

Last Updated: Sep 10 '12 at 12:50 PM