1 decade ago
by Vidd
For example, in Bomberman, you can freely walk over a bomb that someone's placed until you walk out its collision box. For one player, it can be solid but for another player it can be passive.
What's the best way to achieve this in Impact?
1 decade ago
by Joncom
Might be a little tricky because, and I quote a comment in the source code that deals with entity collision, "This is a mess."
There is a function defined as
ig.Entity.solveCollision
in
entity.js
which defines how two entities should be handled when they collide.
You're probably going to want to hi-hack this method and add a conditional statement at the very top, maybe something like:
// Keep in mind that 'a' is one entity and 'b' is the other entity.
if(a instanceof EntityBomb && b instanceof EntityPlayer && b.canPassThroughBombs) return;
else if(b instanceof EntityBomb && a instanceof EntityPlayer && a.canPassThroughBombs) return;
// By returning, you are skipping all the logic which
// prevents entities from passing through each other.
Because of the "mess", hi-jacking this method will not be as simple as it is for most methods in ImpactJS. Normally you can
extend or
inject code. In this case, you are going to have to globally redefine the function like this:
ig.Entity.solveCollision = function(a, b, weak) {
/* your custom code */
/* all the original function code - cannot use this.parent()! */
};
Hope that helps.
1 decade ago
by Vidd
Joncom, thank you very much. Not just the start of the answer but I'd forgotten all about injecting too.
It won't do me any harm to dig down a little into the engine anyway. :)
Page 1 of 1
« first
« previous
next ›
last »