Search Unity

Using Unity to create pseudo-3D graphics?

Discussion in 'Getting Started' started by treedoor, Jan 10, 2016.

  1. treedoor

    treedoor

    Joined:
    Jan 10, 2016
    Posts:
    2
    I saw there was a sticky thread called "Can I make an FPS, RPG, MMO [Insert game] with Unity?" though after scanning through the list I couldn't find what I was looking for.

    When I say pseudo-3D I'm talking about the old 2D racing games from the 80s and early 90s such as Road Rash, Mario Kart, Outrun (which all have their own little intricacies that differ from each other).



    I do know some people have shown off works in progress of pseudo-3D games they made in Unity, but I'm wondering what it takes to reach that point? There are almost no tutorials I can find on how to make this graphical style other than a written document that uses pseudo code here http://www.extentofthejam.com/pseudo/ . I personally don't have enough coding experience to put it together myself even if I understand it.

    I'd really like to get into game development with the ultimate goal of reaching a point of being able to create a game using that style. I've been dabbling with Unity for a bit now, and it seems pretty nifty though I'm not sure if it has built-in functionality fit for this graphical style, so my question is that if I want to create something like Outrun in Unity will it just require learning Unity and C#? Or is it a lot more complex than that?
     
  2. AndreCabral

    AndreCabral

    Joined:
    Jan 11, 2016
    Posts:
    15
    As far as I know, there is no built in pseudo 3D in Unity.

    Without creating complex code to make a pseudo-3D system, what I know you can do is create a 3D scenario, and use 2D sprites for the characters, trees, clouds, etc, and make them always face the camera.
    That way, the game will be something like doom or duke 3D (3D floors and walls, and 2d characters and items).
     
    sean244 likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That's exactly right. Yes, you can do it in Unity, and yes, it just requires learning Unity and C#. As a complete beginner, the thing to do is to forget about this specific goal for a while, and spend 6-12 months doing every Unity and C# tutorial you can get your hands on. Note that "doing" a tutorial means actually doing it, not just watching it; and if you really want to learn, then after you finish following along with the video, throw your project away, close the video, and try to do it again without it.

    Don't worry about whether the tutorials appear to have anything to do with your dream project. If you're learning Unity and C#, then you're learning what you need to do your dream project one day!
     
  4. treedoor

    treedoor

    Joined:
    Jan 10, 2016
    Posts:
    2
    Oh yeah, it's definitely an idea on the backburner, and I keep that in mind as best I can.
    It's just one of those issues where I didn't want to spend years to become proficient with Unity and C# only to find that actually creating this effect requires something beyond my realm of understanding.

    I have also thought about the whole making a 3D game, but placing 2D assets throughout. That's my plan B.It's a consistency issue for the specific project I have in mind.
     
  5. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    in general "everything is possible" and "you can learn everything" it just requires more or less effort, something thats beyond your realm of understanding does not have to stay that way :)

    oh i found this while googling :D

    http://codeincomplete.com/posts/2012/6/22/javascript_racer/

    not unity, but javascript, which unity uses also, should be possible to use that since it's not just pseudo code
     
    sean244 and sheffieldlad like this.
  6. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    a) imho you should learn C# instead of javascript.

    b) the author said:



    Just do what @JoeStrout says, it is excellent advice!
     
  7. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    I linked it not as an example for a good tutorial, but because it's showing the technique being used for creating this pseudo 3D scrolling background :) and that it's likely possible with unity, if he is using javascript, which is usable with unity also. So after he learned C#, unity etc. and went through all that process, he does not need to wonder anymore if it's possible, but rather how he can use his new aquired skills to realize it :) He mentioned that he wanted to know if he wastes his time trying to do it, if he doesnt even know if it's possible with unity.
     
    sheffieldlad likes this.
  8. 825546651

    825546651

    Joined:
    Apr 4, 2016
    Posts:
    1
  9. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hi,

    Here is prototype for pseudo-3D racing graphics with no shades and solid 60 FPS.
    It uses unity "low level" draw calls. Very simplistic project to start with.

    https://github.com/h8man/TurboTrack2D

     

    Attached Files:

    Last edited: May 30, 2020
    Ryiah, Vytswell and sheffieldlad like this.
  10. Vytswell

    Vytswell

    Joined:
    Jul 31, 2020
    Posts:
    4
    Hey, thanks for great concept. Could you please explain how to make traffic cars?
    It’s pretty easy to make static scenery, but traffic is moving, so I’m confused about making it work.
     
  11. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hello @arti42000

    Yeah, traffic if where I didn't found the time to finish this demo.
    I used this material https://codeincomplete.com/articles/javascript-racer-v4-final/ for the project.
    You can find paragraph called "Adding cars" with details how to implement it.

    Basically you would have data with all the cars on the track updated every frame, and render only those in render distance.
     
  12. Vytswell

    Vytswell

    Joined:
    Jul 31, 2020
    Posts:
    4
    As I see, you have structure Line (in file line.cs) to display sprites. It's pretty easy to use it to display trafic cars alongside scenery objects, but I can't figure out how to make them move.

    Also, I couldn't figure out how to determine if car is going uphill or not. It seems that it can be determined by picking Y coordinate of last 2 road stripes and if their difference is less (or more) than 0, it means that road goes up (or down).
    Here is what I found in your code that seems to be related to it
    Code (CSharp):
    1. ref Line p = ref track.lines[(n - 1) % track.Length]; //previous line
    Code (CSharp):
    1. ref Line l = ref track.lines[n % track.Length];
    But it seems to me that Line l picks the farthest stripe, instead of close one, so this method can't be used.
    I also thought about using differential for player Y, if it is more than 0, the road goes up, but I don't know how implement this.
    Looking forward for your help.

    P.S.:
    How can I determine collision between car and sprites on the side of the road? (lampposts, in case of your demo)
     
    Last edited: Jan 3, 2021
  13. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hi,

    If sprite is higher than the player it rolling down, if lower - it climbs up. The same with turning, if car on left of player it turns right, and vise versa. But yeah, you can add meta data to track data, such as incline and curvature and make more adjustments to spites, but don't calculate it on the fly, track is static.
    2d arcade racing is about perception and not accuracy)

    As for collision, in original post its made manually in loop "Colliding with billboards and trees" and "Colliding with Cars", just by comparing its linear size overlap with cars-objects on the same segment.
    Code (CSharp):
    1.   overlap: function(x1, w1, x2, w2, percent) {
    2.     var half = (percent || 1)/2;
    3.     var min1 = x1 - (w1*half);
    4.     var max1 = x1 + (w1*half);
    5.     var min2 = x2 - (w2*half);
    6.     var max2 = x2 + (w2*half);
    7.     return ! ((max1 < min2) || (min1 > max2));
    8.   }
    But as you can see collision made only cars-objects vs player. To improve this, you need to iterate through segments and compare object overlap on segment - behind - in-front.
     
  14. Vytswell

    Vytswell

    Joined:
    Jul 31, 2020
    Posts:
    4
    What language is it? It is not C#.
    What does this function do? x1, w1 and x2, w2 are car and object variables?
    Could you please explain it more on the example of exactly your project?
     
  15. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hello @Vytswell
    It is JavaScript from https://codeincomplete.com/articles/javascript-racer-v4-final/
    This site contains the most information about 2D racing design.
    It is used as
    Code (CSharp):
    1. Util.overlap(car.offset, carW, otherCar.offset, otherCarW, 1.2)
    In paragraph "Updating Cars" there is explained how to implement AI and update all cars on track with this func.

    My project didn't get to the stage of collision detection or traffic, so it doesn't have any context for it. That all should be implemented.

    Maybe I would have some time on this weekend to look at closer. Will see)
     
  16. Vytswell

    Vytswell

    Joined:
    Jul 31, 2020
    Posts:
    4
    Ok, thanks. Also, in this JavaScript project, number of road lanes are defineable, how to make it here?
     
  17. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hi @Vytswell

    Not implemented. Number of lanes predefined in
    Code (CSharp):
    1.             addQuad(grass, 0, p.Y, screenWidthRef, 0, l.Y, screenWidthRef);
    2.             addQuad(rumble, p.X, p.Y, p.W + p.scale * rumbleWidth * screenWidth2, l.X, l.Y, l.W + l.scale * rumbleWidth * screenWidth2);
    3.             addQuad(road, p.X, p.Y, p.W, l.X, l.Y, l.W);
    4.  
    5.             if ((n / 3) % 2 == 0)
    6.             {
    7.                 addQuad(dashline, p.X, p.Y * 1.1f, p.W * 0.05f, l.X, l.Y * 1.1f, l.W * 0.05f);
    8.             }
    9.  
    But you can easily extend this logic. Just add more dash lines on the road depending on track data
    NOTE: quads are drawn symmetrically to the track axis
    I'm glad that you interested in project, and sad that I hadn't time to implement basic feature
     
  18. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hi All,

    Have some updates.

    - Run in edit mode
    - Fix sprites renderer
    - Fix background renderer
    - Add track editor (very basic)

    and more to come

    https://github.com/h8man/TurboTrack2D
     

    Attached Files:

  19. SpaceChicks

    SpaceChicks

    Joined:
    Oct 9, 2012
    Posts:
    22
    Hi guys. Take a look at this
     
  20. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Nice, but is it 2d? looks fully 3d for me.
     
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It is basically just making a 3D title with sprites instead of 3D objects. You still use all the same underlying Unity code you would normally.

    There isn't much to solve here, except maybe choosing which sprite to display for a specific angle. That's also trivial and you can just make a post for that specific problem if you get stuck.
     
  22. SpaceChicks

    SpaceChicks

    Joined:
    Oct 9, 2012
    Posts:
    22
    Nope, the logic behind a Outrun title is different. You're in the same place moving right and left, and there's a track that curves coming at you. You just keep curving the road and adding force to the sides as you curve. That's the logic, that's the feeling.

    upload_2021-8-4_4-49-48.png
     
    vhman likes this.
  23. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,153
    Okay, but that doesn't change the fact that there isn't much to solve. Nothing from that time period is overly complex because the potatoes of the time wouldn't have been capable of it.

    Outrun works by shifting each horizontal line rendered based on how much the track is "curving" and where it is vertically on screen.

    https://codeincomplete.com/articles/javascript-racer-v2-curves/
     
    Last edited: Aug 4, 2021
  24. SpaceChicks

    SpaceChicks

    Joined:
    Oct 9, 2012
    Posts:
    22
    Actually because of limitations and the fact that things were all "pseudo" , its a challenge to replicate the feeling and gameplay in 3d engines. Same could be said of Wolfenstein3d , Delta Force and others. But I agree yes.
     
  25. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,153
    It's only a challenge if you don't know what you're doing. Unity can be set to make everything pixel perfect which is what the so called "2D engines" are doing behind the scenes. In fact there is no such thing today as "2D" in modern systems because even at the hardware level everything is 3D.

    Check the link below. It's one of the few practical and in-depth blog posts made by Unity.

    https://blog.unity.com/technology/2...-up-your-unity-project-for-retro-8-bits-games
     
    Last edited: Aug 8, 2021
  26. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
  27. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Looks quite good that, I'm not generally a fan of driving games but I'd play this.