udisun Posted February 1, 2014 Share Posted February 1, 2014 i have a game in which monsters are generated and are moving to the center of the mapon the way they have obstacles and i need them to be a little bit smarter and "know" they are about to collide so they will try to go around that obstacle. does anyone know how one can achieve that? Link to comment Share on other sites More sharing options...
jerome Posted February 1, 2014 Share Posted February 1, 2014 I'm not specialist but have three clues : - you could have wider bouding boxes than their related visible obstacle sprite. So your monster will actually collide the obstacle but farther than its visible image to the player's perspective. You can then have a collision callback function to change monster moving directions (say, rotate 30° left or right, then try moving ahead with the same constraints).The user won't see your monster collide the obstacles, but maybe hesitate over their way to follow. Not sure they'll look smart - you could either implement vector fields attached to your obstacles.Article here : http://buildnewgames.com/vector-field-collision-avoidance/ (caution it's not plain javascript but pseudo-code) and exemple here : https://mod.it/YCb1159nI think it's not that CPU consuming. Your monsters won't never collide your obstacles then.Will they look smart ? it probably depends upon your obstacle positions. - you can use a A-star algorithm if your obstacles have fixed positions. here is the Phaser plugin : https://github.com/appsbu-de/phaser_plugin_pathfindingYour monsters will use the best, so the smartest, way to reach their goal without colliding any obstacle. Link to comment Share on other sites More sharing options...
udisun Posted February 1, 2014 Author Share Posted February 1, 2014 Thank you for these tips, i actually thought about the first one as a "fake" smart monsters, and i'm using this line to move my monster:monster.rotation = this.game.math.degToRad(90) + this.game.physics.moveToObject(monster, player, 60);Using moveToObject like this actually changes the rotation of my monster while it is colliding with obstacles, so it's really cool.I'm going to investigate the other options you've suggested and report back. Link to comment Share on other sites More sharing options...
Vaughan Posted February 1, 2014 Share Posted February 1, 2014 You want a steering behavior, specifically the avoidance one: http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-collision-avoidance--gamedev-7777 Heppell08 and jerome 2 Link to comment Share on other sites More sharing options...
jcs Posted February 1, 2014 Share Posted February 1, 2014 +1 for steering behaviours. simple vector math and good results Link to comment Share on other sites More sharing options...
Recommended Posts