Posts Tagged ‘camera’

Progress (14 hours in) – Simulation up and running

Posted by
Saturday, December 12th, 2015 8:46 pm

GIF

I strapped a camera to one of the bees, it got beaten up pretty bad…

The simulation works about as it should now. I have the whole day tomorrow to implement interaction mechanics and audio, lucky me!

Update update – 19th August 2015
Just in time for LD33 I’ve updated the base code to add menus, pathfinding and lighting, and tidy it up a little. See the readme on GitHub for details, and a bit of info about things to look out for (don’t enable Unity’s anti-aliasing!).
Oh, and you can now invert colliders if you want auto-tiled roads rather than walls.

Original:
As I was looking forward to LD30 I thought I’d make a little base code to make life easier and maybe allow more exciting designs.

Here it is on GitHub

Anybody can use anything in there for any purpose, but giving Colthor credit would be nice.

Obviously, one can’t use the sprites and tiles for one’s compo game (and probably wouldn’t want to); they’re mostly in there as documentation and to demonstrate that/how the code works.

There’s an entire Unity project as an example, but the important parts are:

 

Camera Script

“Assets/CameraSizer.cs” is the camera script, and it automatically adjusts Unity’s 2D camera so sprites are 1:1 mapped with the screen (or some multiple of). If the script’s PixelsPerUnit is the same as a sprite’s, it’ll be mapped 1:1. If it’s half the sprite’s the sprite will be pixel-doubled, and so on. Textures mapped to meshes (for instance, with the tilemap) or whatnot don’t work like this, o’course, so make sure you size them appropriately.

 

Tilemap with auto-tiling

“Assets/TileMapScript.cs”
is the tilemap. The .cs contains more thorough documentation, but it creates a Squares_X by Squares_Y tile grid, with each square Square_Size units to a side. It gets the data about which tile to use from LevelData, which is just a text string (0-9, A-F are ‘open’ tiles, X indicates a wall, all other characters should be ignored). “Assets/32tiles.png” is an example of the texture required.

The script then auto-tiles the walls, selecting the correct tiles from the given texture, and then adds box colliders for the walls as children to the attached gameobject. To reduce the number of colliders it groups them to cover multiple walls where possible – first making it as many tiles wide as possible, then as many tiles high. It would be possible to use a single polygon collider with several paths, but it would also be considerably more work, sorry 😉  (And maybe not faster.)

The gameobject’s origin is the bottom left corner of the map, and LevelData is mapped in the same way as the tile texture; the first character is the top left, the second row will start – assuming no ignored characters – at Squares_X, and the bottom right will be character (Squares_X * Squares_Y – 1).

 

I’ll try to back-port any improvements or bugfixes made over the course of LD30 for future jams!

 

Diodontidae necandi – almost there !!

Posted by
Sunday, April 19th, 2009 3:52 pm

almost there !!

  • the colisions are ok now
  • the fish eat the food garbage
  • push the batteries to the top
  • counting the number of garbage stuff

still missing

  • the colision to the pig
  • main menu
  • game over
  • score show

[cache: storing page]