bartk Posted October 12, 2015 Share Posted October 12, 2015 Good afternoon, I'm trying to make a small driving game, and I want to limit my player's car so that he can't move off of the roads and on the sidewalks. Might anyone know how to best handle it? I'd rather not add lots of invisible "fences" to collide with the car if I can help it. Cheers. Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 12, 2015 Share Posted October 12, 2015 I believe you're looking for this? http://phaser.io/docs/2.4.3/Phaser.World.html#setBounds This game engine does that work for you already Edit: Nervermind, was thinking about something else, ignore this post my bad. Link to comment Share on other sites More sharing options...
bartk Posted October 12, 2015 Author Share Posted October 12, 2015 Yeah, if I could do something close to that but with an object group, I'd be set. Link to comment Share on other sites More sharing options...
Skeptron Posted October 12, 2015 Share Posted October 12, 2015 Why don't you create a map and set collisions on walls? Do you plan on creating the map dynamically? Link to comment Share on other sites More sharing options...
totor Posted October 12, 2015 Share Posted October 12, 2015 if we have to guess what your game looks like and how is the road drawn it's a bit difficult Link to comment Share on other sites More sharing options...
Cudabear Posted October 12, 2015 Share Posted October 12, 2015 Are you using a tilemap to define your "road"? If so, when I'm using tilemaps I typically make an invisible "collision" layer, full of invisible tiles that are set to collide on all sides. Alternatively, you can individually define collision on the tiles that are actively drawn.If you require collision that's not a bunch of blocks (i.e. tilemap or arcade physics), like polygon or rounded edges, you'll need to use P2 physics. You can probably define the outer walls of the track as one massive polygon and the inner walls as another, smaller polygon. Then check collision on these two polygons and the cars. Mind you, checking collision on large polygons with P2 is pretty slow so limit the number of polygons as much as possible. Link to comment Share on other sites More sharing options...
DonFrag Posted October 12, 2015 Share Posted October 12, 2015 like Cudabear said, it depends of how do you build your road it's how could implement collision check. Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 I have little to no experience with Phaser, or even with gamedesign, so I've just made a few dozen "road" objects with a sprite that's tiled across them. I realize it's possible to just build blocks all around the roads, but I was hoping there'd be a more painless way Here's an example: Link to comment Share on other sites More sharing options...
Skeptron Posted October 15, 2015 Share Posted October 15, 2015 How is that painful exactly? Just having collision tiles? I really can't see any simpler solution, whatever the engine or the method.... Do you use Tiled for building your maps? Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 I'm afraid I don't really know what you mean by Tiled. Basically I've used a 50x150 sprite to build all my horizontal lengths of road, and a 150x50 to build the vertical lengths. One of these lengths may be:roads = game.add.group();...road1 = game.add.tileSprite(0, 400, 150, 800, 'road');roads.add(road1);If there's no other way than to create invisible collision "fences", so be it. Link to comment Share on other sites More sharing options...
Jaspery Posted October 15, 2015 Share Posted October 15, 2015 I recommend taking a look at RPG maker tutorial or similar if you're new at Tile mechanics http://forums.rpgmakerweb.com/index.php?/topic/3331-introductory-guide-to-tiled/http://www.faqoverflow.com/gamedev/8336.html (same concept applicable to other genre) it basically a few layers of graphic that drawn together with 32x32 tiles, and typically a layer of invisible tiles will be the collision that keep the character within the world Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 Interesting, I'll check it out, thanks Link to comment Share on other sites More sharing options...
Skeptron Posted October 15, 2015 Share Posted October 15, 2015 Here you don't need any kind of tiles to keep the player within the world, as you can use the setWorldBounds() method for that. But yeah, you should (/must) look at Tiled : http://www.mapeditor.org/ Making maps is going to become both easy and fun after that. Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 That certainly looks a lot easier than what I've been doing so far Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 By the way, what I'm trying to do isn't to keep the player in the world. That was easily done by world bounds as you said. I'm trying to keep the player limited to the roads, so that he can't drive over the sidewalks or into npcs. Link to comment Share on other sites More sharing options...
Skeptron Posted October 15, 2015 Share Posted October 15, 2015 What you usually do is draw a few tiles (say 3 : sidewalk, road and house tiles). You import these in Tiled and easily build your map, placing the tiles wherever you like it. Then, let Tiled export your map as a JSON file. Import this JSON into Phaser, as well as the image with your 3 tiles, and Phaser will understand how to rebuild the map using your tiles. Then just point to Phaser that the sidewalks and houses tiles are collideable, and the trick is done. Your car won't be able to drive over them. Link to comment Share on other sites More sharing options...
bartk Posted October 15, 2015 Author Share Posted October 15, 2015 Much obliged for all the help Link to comment Share on other sites More sharing options...
Recommended Posts