# Raycasting 3D render -- Blocks Edition

**URL:** <https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921>\
**Category:** Game Design\
**Tags:** game, graphics-and-math, extension\
**Created:** [April 1, 2022, 6:23pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921 "2022-04-01T18:23:28Z")\
**Posts on this page:** 20\
**Page:** 11

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [March 6, 2023, 5:30pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/206 "2023-03-06T17:30:39Z")

</div>

In 3D world overlay condition is a little difference from 2D world. I modified some of your project.

- Jump condition.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e174911d215b7826c9822e7fc025d2251b606f6b.png)  
Focus on Z direction, use overlaps in Z dimension block to filter touching in Z first.  
Then, filter falling state by sprite.ZVelocity\<0  
Then, optional, sprite.ZPosition\> otherSprite.ZPosition + [Height of otherSprite after scale] - AFewToleranceHeight
- Delay with Throttle block of Timer after hurt.  
Avoid pause in event function
- Animation setting.  
Raycasting provided animation setting is more efficient, though the animation of Character extension works, but it update by setImage(), which will trigger many update calculations repeatly we needn’t in our case .(image size, hitbox, overlay objects. etc.)

> **[JumpOn](https://arcade.makecode.com/S67185-78642-69237-94063)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [March 6, 2023, 5:30pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/207 "2023-03-06T17:30:55Z")

</div>

Could you share your project?

---

<div class="post-metadata">

**Author:** ![labfox29](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/labfox29/32/9252_2.png) [@labfox29](https://forum.makecode.com/u/labfox29)\
**Post date:** [March 7, 2023, 4:15am UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/208 "2023-03-07T04:15:20Z")

</div>

what about a top-down view

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [March 7, 2023, 5:01pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/209 "2023-03-07T17:01:25Z")

</div>

@AqeeAqee I made a version of your extension (I hope its ok to post it here) that uses the grayscale color palette, and has a nice fade-in effect to objects while preserving textures! It was made in inspiration by the game that @richard is making in the livestream, and I figured it could be expanded so as to not take up like 15 tiles but instead render at runtime! (sprites not supported in the effect)

The extension is:  
kiwiphoenix364/pxt-raycasting-mod-grayscale

I made a test project (only uses 2 blocks):

> **[spooky](https://arcade.makecode.com/19369-97365-38380-10488)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

There is a new block at the bottom of the list, and the darkness modifier is normally 1, but you can change it with 0 being no darkness at all. The texture visibility determines how bright the textures are, ranging from 0 and higher, with 1 being normal, 0 being white, and colors above 1 getting (quickly) darker as they get higher (you don’t usually want to go above 2). The texture visibility isn’t a recommended setting to change, because leaving it at 1 is optimal most of the time.

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [March 7, 2023, 6:52pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/210 "2023-03-07T18:52:25Z")

</div>

No problem! Glad to see someone improve it.  
Grayscale color is good idea, it render shodow more linear.  
I missed that livestream, let me know which ep and start point, if need me to sync up the context.

BTW, try to change

> - dis / 4 \* this.darknessMod

to

> - dis / this.darknessMod

that should means how many tiles away get 1 step darker. More easy to understand and not increase dark so fast, I think.  
Just a quick idea, didn’t tested 🤣

---

<div class="post-metadata">

**Author:** ![SOCKMONSTER12](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sockmonster12/32/7584_2.png) [@SOCKMONSTER12](https://forum.makecode.com/u/SOCKMONSTER12)\
**Post date:** [March 7, 2023, 7:19pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/211 "2023-03-07T19:19:16Z")

</div>

This is amazing, not capping I love it

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [March 7, 2023, 7:41pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/212 "2023-03-07T19:41:07Z")

</div>

You are right about the code, but it should be “/ 2” instead. The current code divides the lighting and the textures, so certain textures don’t just dissapear when they get too dim, bc that’s awkward imo. It only currently renders half of the colors because of this, but if you set the textureVisibility to 2 and the darknessMod to 0, you would see the full textures. I may change this in the future, but thx! I didn’t mean to divide by 4 there! I made a release that fixes that.

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [March 8, 2023, 1:03am UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/213 "2023-03-08T01:03:44Z")

</div>

Oh~ the key point I mean is " **/ this.darknessMod**", instead of " **\* this.darknessMod**"  
Have you try it?

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [March 8, 2023, 5:23pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/214 "2023-03-08T17:23:05Z")

</div>

After a while of troubleshooting of how to not entirely divide brightness from textures, I found the solution. I ran the loop in reverse, so it would dim the texture from the dimmest to the brightest instead of the brightest to the dimmest. When it was doing this, it just went black because the color was made darker, then the darker color was iterated making it darker, and so on. With 15 colors of brightness it looks more smooth. I expected the darker colors fading into nothingness earlier than the lighter ones to be weird, but apparently that’s realistic anyways and looks totally normal in-game (once I took an hour to troubleshoot something I probably should have figured out a lot sooner.) I also implemented division like you said. It makes decimals below 1 darker faster than normal, and numbers above 1 slower. The negative numbers no longer have the white fog effect, but I guess that’s OK (I might add a block for that in the future). I like how smooth this mod looks, and it barely has an impact on perf from what I’ve seen because it’s only replace color! Maybe eventually I’ll add fade-in for sprites, but not for this update… I made a release for the current features!

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 8, 2023, 9:53pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/215 "2023-03-08T21:53:09Z")

</div>

could i use this code in a game im creating?

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 8, 2023, 9:53pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/216 "2023-03-08T21:53:17Z")

</div>

ive made the exact same thing 2 days ago, but how it works is that it checks if using a wait condition instead of a `sprites overlap` condition.

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [March 9, 2023, 4:23pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/217 "2023-03-09T16:23:56Z")

</div>

No problem! Feel free to use these code.

And, the wait condition is fliped by a fix timespan, right? The time could be vary, eg: ducks can jump. Overlap in Z is the touch condition in Z infact.

---

<div class="post-metadata">

**Author:** ![SizzleStick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sizzlestick/32/7474_2.png) [@SizzleStick](https://forum.makecode.com/u/SizzleStick)\
**Post date:** [March 13, 2023, 5:15pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/218 "2023-03-13T17:15:06Z")

</div>

> **[3d platformer](https://arcade.makecode.com/S45553-54877-34031-90307)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Something.

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 17, 2023, 4:19pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/219 "2023-03-17T16:19:56Z")

</div>

i forgot to put the code, heres the platformer btw if anyone wanna try it

> **[3d platformer 0.2](https://arcade.makecode.com/S73870-75989-35288-15541)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Nerdiest](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/nerdiest/32/10678_2.png) [@Nerdiest](https://forum.makecode.com/u/Nerdiest)\
**Post date:** [March 20, 2023, 5:25pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/220 "2023-03-20T17:25:21Z")

</div>

Nice! Are you gonna add to this? If so I’d love to help! (i’m doing a project right now) but I’m able to do art if needed!

---

<div class="post-metadata">

**Author:** ![SOCKMONSTER12](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sockmonster12/32/7584_2.png) [@SOCKMONSTER12](https://forum.makecode.com/u/SOCKMONSTER12)\
**Post date:** [April 7, 2023, 9:59pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/221 "2023-04-07T21:59:42Z")

</div>

@AqeeAqee I’ve a theory. could you make a background image like the game death run made in the forum, so you press up or down you’ll go up or down (using different keys than the regular up or down) on the screen, but you can still go forward and backward side to side with raycasting?

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [April 8, 2023, 12:39am UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/222 "2023-04-08T00:39:19Z")

</div>

What you want has been done by @technonux, right?

> [@technonux](#):
>
> i forgot to put the code, heres the platformer btw if anyone wanna try it
> 
> [https://arcade.makecode.com/S73870-75989-35288-15541](https://arcade.makecode.com/S73870-75989-35288-15541)

---

<div class="post-metadata">

**Author:** ![TruGamer](https://avatars.discourse-cdn.com/v4/letter/t/958977/32.png) [@TruGamer](https://forum.makecode.com/u/TruGamer)\
**Post date:** [April 12, 2023, 4:03pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/223 "2023-04-12T16:03:33Z")

</div>

How did you get the third person

---

<div class="post-metadata">

**Author:** ![CreativeUsername](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/creativeusername/32/9601_2.png) [@CreativeUsername](https://forum.makecode.com/u/CreativeUsername)\
**Post date:** [April 12, 2023, 4:03pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/224 "2023-04-12T16:03:39Z")

</div>

Is there a way to show text without it cutting to just the background?

---

<div class="post-metadata">

**Author:** ![TruGamer](https://avatars.discourse-cdn.com/v4/letter/t/958977/32.png) [@TruGamer](https://forum.makecode.com/u/TruGamer)\
**Post date:** [April 12, 2023, 4:03pm UTC](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921/225 "2023-04-12T16:03:43Z")

</div>

and how did you get floor and sky

[Previous page](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921.md?page=10)

[Next page](https://forum.makecode.com/t/raycasting-3d-render-blocks-edition/12921.md?page=12)
