Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Quazi 2d hell...

Discussion in 'Scripting' started by zumwalt, May 4, 2007.

  1. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Ok, last night I spent nearly 4 hours until I passed out trying to figure out layering the GUITEXTURES on the camera to get an effect to play as a 2d game.

    Attached is a space invaders clone game I wrote in another languaged called aurora. The code for the game exists in the file called basic.src

    Now, the deal with this, as to why I am posting it, is to show that the 2d layer with transparency is used for the game, the 3d atmosphere in the background is not unlike unity where the fact that everything is in the 3d space. Now, its crappy choppy I know, because of the way that engine handles the game loop and I don't have the movement based on timer, but instead, static positioning.

    So, now my delima, I need to do the same thing in Unity, I can update that exact code to work with in unity, IF I can figure out how to place / update images dynamically on the camera as a guitexture.

    So, if there is an article in the docs that I have completely overlooked on how to test for collision between sprite objects, please link me the url to it so I can see how to check for collisions between sprites.

    That will only work on a PC though since its written for directx9, october release I think. Only other aspect I thought about before my head hit my desk, was to create cubes for all game objects, then check for box collision between the objects and lock them to the x and z for movement.

    The entire game logic is already done.
    That took me about a week to come up with although off and on, so really about 9 hours of programming time and testing.

    Like with everything else, I'll be hammering on this until I figure out how to get it to work the way I want it to.
     

    Attached Files:

  2. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
    Is there a particular reason you are using GUITextures and such to make your 2D imagery?

    Why not just use an orthographic camera for your 2D layer and flat textured polygons for your 2D objects? Much, much easier I presume.

    You can still just have all the 3D stuff rendered with a second camera that isn't set to ortho.
     
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Because I don't know how to...
    That and I haven't found a decent demo / explination or example project that uses it.
    I get lost in the docs so easily.
     
  4. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
    Oh, okay.
    Attached is a little project I threw together.

    What to look for:
    The camera settings are important. Notice that the depth is different. The foreground camera renders "on top" so it has a number higher than the background camera. Also, the foreground has ortho turned on.

    In addition, they have different Culling Masks.

    I added a layer called background and set all the cubes to it (well, just once in the prefab, of course.)

    The foreground camera renders everything but objects in the background layer.
    The background camera renders nothing but the background layer.

    Anyway, hope it helps.
     

    Attached Files:

  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Thanks a ton!
    I'll get a chance to look at the project as soon as I get home from work. Thanks again for taking the time to help with this.
     
  6. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    May be hard to understand at first (as anything), but you can do 1000% more with a 3D environment flatted to a plane with an orthogonal rather than with a collection of GUITextures. Work on XY and think as the Z component as the order in which they are rendered.

    You can work with 3D objects and do a lot more effects.

    Take a time to learn it and drop your first attempt, it's worth it.

    Omar Rojo
     
  7. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    The only problem is that this does not work together with Image Effects like glow...
     
  8. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    My only concern is with collision.
    Edit, ok more concern than just collision.
    I need to make sure my bounding game area is constant and accurate to resolution.

    So say the user has a game area of 1024x768, I need to make sure the game components do not go outside the screen width which is not based on the camera.
     
  9. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    This shouldn't be too hard to do in scripting--

    Otherwise, you could always make your 2d objects have depth--simply extruded into 3d--which you wouldn't see in an orthogonal camera anyway, but would enable some basic collisions
     
  10. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    This shouldn't be too hard to do in scripting--

    Otherwise, you could always make your 2d objects have depth--simply extruded into 3d--which you wouldn't see in an orthogonal camera anyway, but would enable some basic collisions
     
  11. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I've thought alot about that today, I have 3d models now of my space invaders components, I should be able to get box collisions between the two, we'll see how this works out tonight, got alot of thinking to do on it.

    I created a manager cube that is behind the camera where all my scripts are attached for the game itself, now I need to add scripts to these new game components and see how I can get them all in synch. In my current model (code in the first topic thread), I have an arraylist of invaders, these all move in unisen with each other, and each row stays in sync, when any of the rows hit the side of the screen width, the entire playing field of invaders knows how to move.