1 decade ago
by Ant101
I would like to create a custom collision type, so that I can detect that the player has collided with this type of tile in .handleMovementTrace() (e.g. to alter player properties based on this.
However, as far as the static collision detection code is concerned, I would like it to behave like a normal 'full collision' tile (ie. type 1). However, I don't see how I can do this, just by extending the tileDefs in ig.CollisionMap.defaultTileDef. It seems that I can only define slopes here?
Can anyone point me in the right direction?
Thanks
Use Impact 1.18. Unfortunately, custom collision tiles were removed in 1.19. I believe Dom is planning to fix this in a future version, but don't quote me on it.
In 1.18, you can specify a collision tileset and test for a tile like this:
handleMovementTrace: function( res ){
this.parent( res );
if( res.tile.x === 4 ){ //say 4 = a water tile
//do something
}
}
1 decade ago
by Ant101
Oh right. I don't know if I have access to that. I recently purchased license - do we get older versions included?
The code you posted is what I'm doing at the moment. But the trouble is the tracing code seems to tread everything that's not 1 as a slope.
If you change your download url to grab /impact1.18zip vs /impact-1.19.zip.
That's the issue: Dom defined all collision tiles > 1 to be slopes, when slopes should be defined as tiles > 1 && tiles < 55.
I got this working in 1.19. I use it for laying out water so my player switches to swimming. I use tile [EDIT] 46. I'll post code later.
This might not be exactly what you want here's what I use in my player.js:
handleMovementTrace: function(res) {
var waterTile = 46; //46th tile on collision tiles changed to be water (by default it is empty)
//if no collision with ground, wall or slope, then could be water // phase transition ensures it doesn't flip back and forth instantly in an endless loop
if (this.phaseTransitionTimer.delta() > 0 && (!res.collision.x || !res.collision.y )) {
var offsetY = this.size.y/2; // player centre
var offsetTileX = (this.flip) ? -1 : 1;
var yTilePos = Math.round((this.pos.y + offsetY) / 16); // tile size = 16
var xTilePos = Math.round(this.pos.x / 16) + offsetTileX;
tileAt = (yTilePos >= 0) ? ig.game.collisionMap.data[yTilePos][xTilePos] : null;
// if tile in 2nd column, 5th row of collision tileset as per version 1.19 of ImpactJS
if (tileAt == waterTile){
// in water. do swimming action. In this case, generate the swimming player and destroy the normal one
ig.game.spawnEntity(EntityPlayerSwimming, this.pos.x, this.pos.y, {flip: this.flip});
// generate some splash debris
for (var i=0;i<2;i++){
ig.game.spawnEntity(EntityDebriswaterParticle, this.pos.x + (Math.random() * 30) - 15, this.pos.y + (Math.random() * 30) - 15, 0);
}
//done with this player because swimmer now generated to take its place.
this.kill();
}else{
// not in water, carry on as usual
}
}
this.parent(res);
},
1 decade ago
by Ant101
@Quidmonkey - ok, thanks
@stahlmanDesign - thank you, I'll take a closer look.
Another workaround would be to create another map layer and call it "custom-collision". You could then test for tiles on this layer and resolve collisions yourself. Be aware that Impact would not perform a movement trace for you on this map.
You could also try to modify ig.CollisionMap._traceStep on line 87:
if(
t == 1 || // fully solid tile?
t > 55 || // fully solid custom tile?
(t > 1 && this._checkTileDef(res, t, x, y, rvx, rvy, width, height, tileX, tileY)) // slope?
) {
if( t > 1 && t < 56 && res.collision.slope ) { // add custom solid tile check
break;
}
// full tile collision!
res.collision.x = true;
res.tile.x = t;
res.pos.x = tileX * this.tilesize - pxOffsetX + tileOffsetX;
break;
}
I haven't tested this, so no idea if it'll work. Be aware, you'll still have to get around the issue of no custom collision tile editing in WM on the collision layer.
I changed the colour of the tile I wanted to be water, and I can lay out the water on the collision layer in WM.
Page 1 of 1
« first
« previous
next ›
last »