Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

2d grayscale variable-map

Discussion in 'Scripting' started by Unitard, Aug 22, 2008.

  1. Unitard

    Unitard

    Joined:
    Jan 27, 2008
    Posts:
    29


    Ok, here's what I have in mind. The mesh below represents my whole map. The grayscale image above it is invisble/internal, but every point on the map that an object can be or go corresponds to a point on the image and thus a value from 0 to 255.

    Then I use the gray value to modify some variable in a script attached to the object. (The map doesn't belong to that specific object, any object can access it.)

    But I also want to be able to modify (generally, add or subtract a fuzzy-edged circular spot) this image in-game using scripting.

    Is there a way to do this?

    Easily?

    Little help, please? (I can't yet Javascript my way out of a wet paper bag.)

    Or is this a stupid way to go about it anyway?
    The alternative to accomplish the same thing is to create an invisible object in world space that has a falloff radius and a decay time and check for and average the influences of all such nearby objects. I'm worried that late in the game the map would be cluttered with these influence objects and slow things down too much. The image would be expensive to "write", cheap to "read", but "read" events will be far more frequent.

    I think I also want to have non-editable maps corresponding to individual terrain tiles- for example- probability that a certain decorative plant or powerup will appear there.
     
  2. Unitard

    Unitard

    Joined:
    Jan 27, 2008
    Posts:
    29
    I'm not using Unity Terrains for my "terrain." The terrain engine is a cool feature but specialized in the wrong ways for what I want my game to look like.

    I'm using ordinary mesh objects- lots of them, tiled together.
     
  3. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    I'm afraid you'll need to build something yourself for this. How will the terrain be textured? Are these simple tiles or will they have to be blended textures like the unity terrain? I've something simple made that I use for my own project (although possibly I'll have to revamp that part in near future). It's written in C# and basically it makes for every tile type a mesh using a height-map (currently a 2-dimensional array, but that isn't that different from a grey-image). It also generates a separate mesh of all tiles for the collision mesh.
    Furthermore for performance reasons, you can have the area split in several subarea's (for example a field of 20x20), because modifying one point means to rebuild the meshes affected completely, so with a 'huge' (say 100x100 or bigger) terrain the modification would give an annoying delay.

    If you're interested I could give you the code (have to remove some dependencies to other code first) but it's basically prototyping code so not that readable and I wouldn't be able to give much support on it (hey I've got deadlines, you know ;-)).

    To see the code working you can find a test build of my project so far (not far) at http://ctrl-j.com.au/pages/vogelspot.html
     
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    jkreijkamp - sorry to divert this thread but the "auto focus" function in your demo is -very- cool. If you don't mind my asking, how'd you do it?
     
  5. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Nah, I don't mind, it's basically the DoF code from the ShaderReplacement (http://unity3d.com/support/resources/example-projects/shader-replacement) code (only ported to C# and made some small tweaks).

    To calculate where to focus I do simple cast some rays from a few points in the centre of the screen. If you like I can give you the code, although there are some dependencies to my other code, like the camera has 'preference' to focus on a bird and stuff like that. Just let me know.
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    That's what I thought. The effect is really very nice. I started to work on something similar the other day. Yes, I'd love to see yours to compare.
     
  7. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    I'm uploading the source and webplayer so have fun with it!

    http://ctrl-j.com.au/pages/showdof.html
     
  8. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Cheers mate! That helps a lot! :)