# Pseudo 3D racer

**URL:** <https://forum.defold.com/t/pseudo-3d-racer/63745>\
**Category:** Questions\
**Created:** [October 24, 2019, 12:26pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745 "2019-10-24T12:26:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [October 24, 2019, 12:26pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/1 "2019-10-24T12:26:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gianmichele](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gianmichele/32/24028_2.png) [@gianmichele](https://forum.defold.com/u/gianmichele)\
**Post date:** [October 24, 2019, 12:36pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/2 "2019-10-24T12:36:22Z")

</div>

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:  
[https://github.com/Foppygames/max-downforce](https://github.com/Foppygames/max-downforce)

Maybe it can serve as inspiration 🙂

---

<div class="post-metadata">

**Author:** ![amel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/amel/32/27475_2.png) [@amel](https://forum.defold.com/u/amel)\
**Post date:** [October 24, 2019, 1:09pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/3 "2019-10-24T13:09:39Z")

</div>

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

> [@Best Method To Make 3rd Person Car Race Game?](https://forum.defold.com/t/best-method-to-make-3rd-person-car-race-game/24810/5):
>
> 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. As usual, google has some good resources on making games: [http://www.extentofthejam.com/pseudo/](http://www.extentofthejam.com/pseudo/)[http://kometbomb.net/2016/04/03/how-does-pico-racer-work/](http://kometbomb.net/2016/04/03/how-does-pico-racer-work/)[https://codeincomplete.com/posts/javascript-racer-v1-straight/](https://codeincomplete.com/posts/javascript-racer-v1-straight/) The first link helped me a lot when I did a racer a couple of months back. I chose to rasterize the image mysel…

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [October 24, 2019, 3:12pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/4 "2019-10-24T15:12:16Z")

</div>

> 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”.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [October 24, 2019, 3:54pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/5 "2019-10-24T15:54:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [October 24, 2019, 3:59pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/6 "2019-10-24T15:59:07Z")

</div>

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

> [@2d light implemetations](https://forum.defold.com/t/2d-light-implemetations/3636/5):
>
> You want to change the vertices in the vertex shader. However, this is tricky, since 1) we’re using OpenGLES 2.0 which doesn’t feature gl\_VertexID, and 2) We currently only support 4 user defined constants per shader. However, a simple test allowed me to modify the vertices of my box, using a custom material and custom shader. The yellow rectangle is the original location of my box, and the gradient polygon is my custom vertices (pretend there’s a light source in the bottom left corner):

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [October 24, 2019, 4:04pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/7 "2019-10-24T16:04:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [October 24, 2019, 4:19pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/8 "2019-10-24T16:19:27Z")

</div>

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 😆

[https://forum-defold-uploads.b-cdn.net/original/3X/6/6/66d37adea79f9c403a4cf36a946668832f183eb0.mp4](https://forum-defold-uploads.b-cdn.net/original/3X/6/6/66d37adea79f9c403a4cf36a946668832f183eb0.mp4)

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [October 24, 2019, 6:37pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/9 "2019-10-24T18:37:27Z")

</div>

[This song](https://www.youtube.com/watch?v=GwlU_wsT20Q&feature=youtu.be&t=80) started playing just as I ran the video. Gave it kind of a transcendental feeling.

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [October 25, 2019, 8:39am UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/10 "2019-10-25T08:39:59Z")

</div>

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](https://forum-defold-uploads.b-cdn.net/original/3X/7/6/76e051a1cc6b1c85c8272f49f826dfbf4a9b2e74.png)

---

<div class="post-metadata">

**Author:** ![Johan](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan/32/127_2.png) [@Johan](https://forum.defold.com/u/Johan)\
**Post date:** [October 25, 2019, 2:47pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/11 "2019-10-25T14:47:14Z")

</div>

When I made [198X](https://www.youtube.com/watch?v=Avbkptw6mSM), 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/articles/javascript-racer-v1-straight/](https://codeincomplete.com/posts/javascript-racer-v1-straight/) and [https://www.youtube.com/watch?v=KkMZI5Jbf18](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.

---

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [October 25, 2019, 5:16pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/12 "2019-10-25T17:16:07Z")

</div>

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.

[https://forum-defold-uploads.b-cdn.net/original/3X/9/3/938eacf449db89670ed3044ff87a4d63430adda5.mp4](https://forum-defold-uploads.b-cdn.net/original/3X/9/3/938eacf449db89670ed3044ff87a4d63430adda5.mp4)

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [October 25, 2019, 5:47pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/13 "2019-10-25T17:47:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benjames171](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/benjames171/32/34759_2.png) [@benjames171](https://forum.defold.com/u/benjames171)\
**Post date:** [October 25, 2019, 5:56pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/14 "2019-10-25T17:56:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 25, 2019, 7:22pm UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/15 "2019-10-25T19:22:31Z")

</div>

> [@jhonny.goransson](#):
>
> vertex attribute för vertex id’s if you want.

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!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 27, 2019, 6:22am UTC](https://forum.defold.com/t/pseudo-3d-racer/63745/16 "2019-10-27T06:22:18Z")

</div>

A pico-8 tutorial about pseudo 3d racers: [Creating a pseudo 3D racer](https://www.lexaloffle.com/bbs/?tid=35767)
