A single entity with multiple collision types. (a sword is both collision type "damaging" and collision type "impassable")


(Helios) #1

Is there any way to do this?

Each entity has a number of listeners for a number of different kinds of collisions. If it collides with something impassable, it will stop moving, if it collides with something damaging, it will take damage.

Many things should trigger multiple listeners.

Again, that is not one behavior that is triggered by multiple types of entities, – it is one entity that triggers multiple kinds of behaviors



edit: for what its worth, I have an easy solution to home brew this functionality. I just want to know if the functionality exists by default.

heres my solution:

First, I default everythings inherited type to "generic".

Then, I give all entities a public variable collisionTypes:Objectthat holds their various types.

Finally, when I check for a collision, I always check thing.collide("generic",x,y).
Then, I put the body inside of an if statement. like so:

impassableListener():Void
{
     if(thing.collidething.collide("generic",x,y))
     {
          var collidedEntity = thing.collide("generic",x,y);
          if(collidedEntity.collisionTypes has element "impassable")
               {
               //don't let the thing pass
               }
     }
}

(Martí Angelats i Ribera) #2

The problem is that you can’t have 2 types in the same entity.

I think you can do two things:

  1. Create 2 entities and put them together (an entity don’t need to have a graphic to have a collide box).
  2. Make a public variable in your enetity class and make every entity that damages or is impasible to have the same coliding type. Then just check if the enetity that you collided with is any of that types (you can also use two Boolean).

(Helios) #3

Phenomenal Idea, I was actually just toying with that first option. Ive actually decided that every entity will have a set of “collision listeners”(i.e. things that listen for collisions of a certain type at a certain place) and “collision causers”(childed entities with their own hitboxes that trigger certain collision types)

For instance, a sword would be composed of three different collisionBehavior objects.

  1. an entity with the collision causer type “damaging” – so anything that had a corresponding “damageable” listener would be damaged if it touched this.

  2. an entity with the collision causer type “impassable” – so anything that had the corresponding “solid” listener can not pass through it.

  3. a collision listener of type “solid” – so that it can’t pass through any other entities which are composed with an “impassable” collision causer (including other swords :smiley:)