sapfeer0k Posted March 10, 2014 Share Posted March 10, 2014 Hello, folks! I'm making simple game, "Landing on the Mars". This is a link http://projects.lomakov.net/html5/Racing/index.htmlCurrently, I'm stuck with the ground generation. I'm using a poligon to emulate uneven ground. But, in this case, physics system works wrong Collision doesn't happen with polygon body, but little above its borders. I've tried to play with body.translate(), but got nothing And second question, how can I fill the ground polygon with texture? I've tried Pixi mask, but no luck Any help very appreciated! :-) Code: function groundGenerator(){ var points = []; points.push(0); points.push(getRandomInt(0, 50) - 30); for(var x=getRandomInt(50, 150); x<1024; x+=getRandomInt(10, 100)) { points.push(x); points.push(getRandomInt(0, -150) + 10); } points.push(1024) points.push(0); points.push(1024) points.push(49); points.push(0) points.push(49); return points;}function create(){ game.physics.gravity.y = 15; bg = game.add.tileSprite(0, 0, 1024, 512, 'background'); bg.body.allowGravity = false; ship = game.add.sprite(512, 100, 'ship'); ship.body.collideWorldBounds = false; ship.anchor.setTo(0.5, 0.5); ship.body.setPolygon(5, 5, 30, 5, 30, 35, 5, 35); var points = groundGenerator(); ground = game.add.sprite(0, 512 - 50, 'ground'); ground.body.setPolygon(points); ground.body.backgroundColor = '#111111'; ground.body.allowGravity = false; ground.body.immovable = true;}function collisionHandler(ship, ground){ console.log("ship landed"); isLanded = true; console.log(vSpeed); if (ship.angle != 0 || Math.abs(hSpeed) > 20 || vSpeed < -40) { ship.kill(); explosion = game.add.sprite(ship.body.x, ship.body.y, 'explosion'); setTimeout(function() {explosion.kill();}, 150); // explosion } else { resetPhysicsOnLanding(ship); } acceleration = 0;} Link to comment Share on other sites More sharing options...
Alvin Posted March 10, 2014 Share Posted March 10, 2014 First , which version of Phaser are you using ? Link to comment Share on other sites More sharing options...
jerome Posted March 10, 2014 Share Posted March 10, 2014 according to console log, seems to be 1.1.6 Link to comment Share on other sites More sharing options...
sapfeer0k Posted March 11, 2014 Author Share Posted March 11, 2014 Sorry, i forgot to mention phaser version. I took the last master version on github https://github.com/photonstorm/phaser, Jerome is right. I also add game.debug.renderSpriteBody(ground); to my render function , and I can see now, that collision happens with sprite's borders instead of polygon coordinates Link to comment Share on other sites More sharing options...
rich Posted March 15, 2014 Share Posted March 15, 2014 If it's colliding with the polygon bounds and not the polygon itself the most common cause of that is that your poly isn't a proper convex polygon, maybe some points are intersecting or the angles are too much, so it's failing to build and resorting to a rectangle. http://en.wikipedia.org/wiki/Convex_and_concave_polygons sapfeer0k 1 Link to comment Share on other sites More sharing options...
sapfeer0k Posted March 15, 2014 Author Share Posted March 15, 2014 If it's colliding with the polygon bounds and not the polygon itself the most common cause of that is that your poly isn't a proper convex polygon, maybe some points are intersecting or the angles are too much, so it's failing to build and resorting to a rectangle. http://en.wikipedia.org/wiki/Convex_and_concave_polygons Thanks for the response! Yes, you're right. My polygon is a concave polygon. Could you give me any other clue how to emulate uneven ground? Link to comment Share on other sites More sharing options...
Recommended Posts