Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by dungeonmaster

I have two entities : fish and food.

I want to detect wheter the fish collided with the food (touched) and if so remove the food.

Fish has two states, hungry or full. If the fish is full, then it shouldn't touch nor collide with the food. All fish start as hungry and become full if they touch the food. I overwrote its collideWith like this. (isFood is a custom property I added)

    collideWith: function( other, axis ) {
	if (other.isFood && this.hunger > 900) {
	   other.kill();
	   this.hunger = 0;
	}
    },

I set colisions of entityFood as .LITE and entityFish as .ACTIVE. I've also overwritten collideWith of food to not have it move like this:

    collideWith: function( other, axis ) {
        // Don't do anything stupid
    },

Problem 1) If a fish is full and it touches food. It pushes the food away. I want the food to just stay in it's position without actually colliding.

Problem 2) The fishes collide with each other. I don't want it either.

Any ideas?

1 decade ago by philnelson

Have you looked into the PASSIVE collision type? Passive collisions will still trigger the collision logic, but neither entity will be physically displaced by it, they merely overlap visually.

1 decade ago by quidmonkey

Use .PASSIVE type and .check() vs. .collideWith().

1 decade ago by dungeonmaster

Thanks, it worked like this:
Fish:
    check: function (other) {
	if (other.isFood && this.hunger > 500) {
	other.kill();
	this.hunger = 0;
	}
    },

1 decade ago by city41

So far I'm finding impact's hit detection system pretty confusing. It's one area I hope gets a nice refactoring in 2.0
Page 1 of 1
« first « previous next › last »