evilwizard Posted May 7, 2017 Share Posted May 7, 2017 I am creating a platforming game that has multiple different platforms. Some platforms slope up and others slope down. Upward Sloping Platforms * If the character moves right, his y position will increase * If the character moves left, his y position will decrease * The angle property of these platforms is negative Downward Sloping Platforms * If the character moves right, his y position will decrease * If the character moves left, his y position will increase; * The angle property of these platforms is positive The following tries to find the colliding platform. My update function looks something like this game.physics.arcade.collide(hero, platforms, function() { currentPlatform = platforms.children.filter(p => p.getBounds().contains(hero.x, hero.y))[0]; gameState.moveRight(); gameState.moveLeft(); }); } I need this platform to calculate whether the character will move upwards or downwards. Here is an example if (cursors.right.isDown) { if (currentPlatform) { hero.y = currentPlatform.angle < 0 ? hero.y - 0.04 : hero.y + 0.04; } } This obviously doesn't work, and the 0.04 value is hard coded, because I can't figure out how to increment with an angle. I've also tried calling sprite.body.touching, which returns the following Object {none: true, up: false, down: false, left: false, right: false} I am completely lost right now. Link to comment Share on other sites More sharing options...
evilwizard Posted May 7, 2017 Author Share Posted May 7, 2017 I managed to solve the angular velocity with the nifty game.physics.arcade.velocityFromAngle function.. However, the problem of detecting the current platform the sprite is on persists. Link to comment Share on other sites More sharing options...
samme Posted May 8, 2017 Share Posted May 8, 2017 It will be in the arguments to the callback: game.physics.arcade.collide(hero, platforms, function(collidingHero, collidingPlatform) {/*…*/}); evilwizard 1 Link to comment Share on other sites More sharing options...
Recommended Posts