How do I check for a collision tile I created on the collision layer in weltmeister?
In particular, I'd like to know if I can check for it in either handleMovementTrace() or collideWith()
1 decade ago
by dominic
handleMovementTrace()
is called for "static" collisions - that is, collisions with the collision map. This is where you can check with which tile an entity colided with.
collideWith()
on the other hand is only used for "dynamic" collisions - collisions between two entities.
I need to override handleMovementTrace() so that Impact's bounciness physics only work for collision layer tiles. But I want it to ignore Impact's physics when colliding with any Entity. How do I do that?
I already have my collision logic setup to run in collideWIth(), but in order to do that, my current handleMovementTrace() looks like this:
handleMovementTrace: function ( res ){
this.pos = res.pos;
},
Which prevents collision with collision layer tiles.
To clarify, what I'm looking for is something like this:
handleMovementTrace: function ( res ){
if ( collisionMap[res.tile.y][res.tile.x] == collision tile)
this.parent( res );
else
this.pos = res.pos;
},
Do you just not want entities to be able to collide at all (they can just pass through each other?) If so, there is a really easy set that using the
collides property:
EntityFoo = ig.Entity.extend({
collides: ig.Entity.COLLIDES.NEVER
init: function (x, y, settings) {
// the rest of your entity stuff
});
You can also set which entities will bounce, etc by using different COLLISION modes. Check out the
collision tutorial for more.
No. I have a Ball entity that I want to control how it collides with Entity. However, I also need it to collide with collision tiles. Unfortunately, the only way I've found to easily write my own collision logic is to override the handleMovementTrace() so that it does nothing and then implement the physics with collideWith(). As Dom points out above, I can take care of all the Entity collisions with collideWith(); but collideWith() does not handle collision layer tiles - only handleMovementTrace() does that. However, handleMovementTrace() also handles collisions in general and interferes with my collideWith() logic. I need a way around that.
1 decade ago
by dominic
I don't get it. What's the goal of all this? What are you trying do to? Maybe there's some easier way!?
Quote from quidmonkey
However, handleMovementTrace() also handles collisions in general(...)
.handleMovementTrace()
is called for each entity for each frame. The function is called whether the entity actually collided with a tile or not. You can check the
res
property
if a collision occurred.
If you want to ignore certain tiles of your collision map, you have to compute the new position of the entity yourself. E.g.:
handleMovementTrace: function ( res ){
// ignore collisions for tile nr. 5
if( res.tile.x == 5 || res.tile.y == 5 ) {
this.pos.x = this.vel.x * ig.system.tick;
this.pos.y = this.vel.y * ig.system.tick;
}
else {
this.parent( res );
}
}
Dom, what I'm trying to do is this: I have a Ball, and it can collide with a Paddle, a Block or the Wall. The Paddle and Block are Entities. The Wall is the Main layer that's linked to the Collision layer. I want to have the Ball react differently depending on what it's colliding with.
//pseudo code
if ball collides with paddle
do first type of velocity change
if ball collides with block
do second type of velocity change
if ball collides with wall
do third type of velocity change
The first two I can take care of in collideWith; the third one I don't know how to test for since the Wall is not an Entity. I may be wrong here, but I overrided handleMovementTrace() because I don't want the basic reflection/bounciness physics defined there.
1 decade ago
by dominic
Yep, then
handleMovementTrace()
is what you need.
handleMovementTrace: function ( res ){
if( res.collision.x || res.collision.y ) {
// This entity collided on either the x or y axis,
// the collision pos is res.pos.x, res.pos.y.
// Do whatever you want here.
}
else {
// No collision. Just move normally.
this.parent( res );
}
}
Thx, this helped, although it wasn't what I was looking for. It did make me go back through my code and find the source of the error. Thx for the help!
Page 1 of 1
« first
« previous
next ›
last »