Pseudo 3D racer

Has anyone attempted a pseudo 3D racing game using Defold? I mean games like Outrun.

I’m sure it’s possible but so far the only ways I can imagine drawing the track are quite limited and inefficent.

2 Likes

This is something that is always in my mind but never had time to try.

I’ve seen recently a good version in love2d here:

Maybe it can serve as inspiration :slight_smile:

2 Likes

I was reminded of this post. Perhaps it’s useful.

4 Likes

There are different ways of doing this.
E.g. skewing 2d sprites to create arbitrary polygons, to get a 3D perspective.
You can also rasterize the polygons yourself.

How would I go about that? I’ve been trying to do this for the last couple of days, but I couldn’t make it work.

I tried to add a transform matrix to a shader, but I couldn’t make it independent of the world position. I ended up just modifying the coordinates of specific vertices to force it into the shape I wanted, but that breaks the texture, as the sprite is made of two triangular polygons and moving a vertex only skews half the sprite the right way.

I ended up just going with that, as it’s not that bad and it was meant to be just a simple practice project anyway, but I’d like to know what’s the correct way to do that. I did learn a lot about shaders, though, such as “what the hell is a shader”.

1 Like

I should try to find that source and put it up somewhere ^^

2 Likes

Here’s one way. Since it uses uniforms, it will break batches, but could still be useful sometimes:

1 Like

Thanks! I’ll look into it when I have the time. Looks like I wasn’t that far-off.

I’m trying a method that’s based on using horizontal scanlines rather than polygons. It’s quite limited in how far your can distort the road round a corner or view it from weird angles. At least, I imagine it will be, I haven’t got that far yet :laughing:

5 Likes

This song started playing just as I ran the video. Gave it kind of a transcendental feeling.

Hmm… that doesn’t solve my problem. In fact, it’s pretty much the same partial solution I ended up with, I think (which is a huge confidence boost, btw!).

I added a simple grid texture to your example and changed the shape a bit to make it more clear and this is the result:

nope

When I made 198X, I started thinking of ways to do it in Defold, but my lack of solutions for pseudo racer rendering was one of the things that made me go for another engine (then I ended up making it in Compute shaders and totally custom anyway, but that is a different story). I did however get a lot of good ideas regarding how to handle things mathematically from both https://codeincomplete.com/posts/javascript-racer-v1-straight/ and https://www.youtube.com/watch?v=KkMZI5Jbf18. The latter might be a little too much on the kindergarten-computer-class-side of things, but he has a few good and simple solutions to some problems.

3 Likes

Sort of got curves working though it really needs a scrolling horizon to sell the effect. The overall techincal difficulty is not that hard if you build up functionality in stages. Could add hills to this without too much trouble. Probably not going to take it any further though as it doesn’t actually loook that great compared to a polygon based approach.

5 Likes

We will be releasing custom vertex buffers pretty soon (it’s in review atm) which means you can generate mesh data in any way you prefer, even in runtime. Would that help? You could have a separate vertex attribute för vertex id’s if you want.

5 Likes

That’s sounds really good. I’ll take a look at it upon release.

I love how you snuck in a bit of Swedish there! Let’s slowly start converting API functions and some manuals to Swedish and see when the community notices!

7 Likes

A pico-8 tutorial about pseudo 3d racers: https://www.lexaloffle.com/bbs/?tid=35767

1 Like