RayCaster

RayCaster

by ADDmonkey55

👁 47 ❤️ 0 ⭐ 0 🔄 0
Created: Jan 23, 2021 Last modified: Feb 2, 2021 Shared: Jan 23, 2021

Description

~:~ Best to view this on turbowarp.org/477817645 My Ray caster that supports angled walls. So I learned about Ray casting from Youtuber 3DSage (youtu.be/gYRrGTC7GtA), and I did a little bit of studying up from Lode's tutorial (lodev.org/cgtutor/raycasting.html). I wrote my own code in OOP pseudo code, but I legit couldn't figure out how to draw pixels (I'm still learning non-Scratch coding). Then one day I came up with an idea for slanted walls ray casting... which is actually not very efficient speed wise (calculations have to be done for each ray for each existing segment, as opposed to the common grid based algorithm where calculations are needed just for each ray regardless of how many "walls" there are). I'm sure this algorithm is fairly common, but I'm still proud that I figured it out. Basically for each ray cast, it checks where it would intersect each wall, then checks if that intersection is within the range of the wall, then just gets the closest intersection. I decided this was easier to implement here in Scratch than the Grid based algorithm (but I could be wrong...idk) When running in Turbowarp with Screen Width set to 480, it can maintain 60 fps up to about 100 segments, and starts to drop under 30 fps past 200 segments (dropping close to 20 fps at around 300 segments). Of course these numbers double when Screen Width is instead set to 240, which still looks just fine. There's still a lot I want to do to make this into a more fully fleshed out actual textured ray caster, which includes: TODO: ▸ Implement portals (an idea I've had for a while that will allow for non-Euclidean. I'm very excited for this!) ▸ Fix collision so it's not "sticky" (this is a lot harder than it should be...) ▸ Implement a Binary ray casting method (another idea I had to speed things up, and I'm sure it's been done before but I don't know what it's officially called) that will greatly speed things up (although there's a drawback). Basically cast a ray on both sides of the fov and then recursively cast a ray in the middle and keep dividing until 2 rays hit the same segment so we know what all the in-between rays will be. This limits islands (if you can see the same segment to the left and right of another segment, that latter segment may not be rendered at all). ▸ Implement textures. ▸ Add floor/ceiling textures. ▸ Add sprites ▸ Walls with transparency ▸ Different height walls ▸ Better gui for creating levels ▸ Other stuff for a full game ^_^ These things are just too complex (for me) to implement in Scratch. I want to carry this onto C#, which I am currently learning (more specifically Unity, which I know Unity can do 3D graphics anyway, but that's besides the point) LET ME KNOW WHAT YOU THINK!!!!

Instructions

~:~ Best to view this on turbowarp.org/477817645 CONTROLS: ▸WASD - Move ▸Left/Right arrows - Turn ▸Click & Drag (while in 3D view) - Turn ▸2 - Switch to 2D map mode ▸3 - Switch to 3D view ▸V - Show/Hide variables 2D MAP MODE: ▸ZX - Zoom in/out (about mouse pointer) ▸F - Toggle follow mode on/off ▸Click & Drag - Move camera (with follow mode off) ▸Hold Space to select a line segment. ▸While a segment is selected, you can: ▸Click & Drag - Move and end point ▸C - Recolor ▸0 - Delete Segment ▸Hold C (when not selecting) to: ▸Click & Drag - Create a new segment ▸G - Toggle Grid snapping on/off 3D MODE: ▸B - Change Background ▸Hold M to Save, Load, or Clear the current map. Saving and loading works via generated code. Simply copy and paste the code. (Saving will show a list that you can copy the text from. Pressing M will hide the list) ````````````````````````````````````````````````` EXPLANATION ON ADJUSTABLE VARIABLES: ▸Screen Width: How many rays are cast per frame. Turbo Warp can support the full 480 pixels. Scratch will start to lag past 30 columns. ▸FOV: Field of View. 60 looks natural and is used by most ray casters. 360 turns you into a floating eyeball creature whose pupil wraps all around. Have fun playing with extreme values! ▸Mouse Sensitivity: For turning with the mouse in 3D View. ▸Turn Speed: For turning with the arrow keys. ▸My Speed: Player's move speed. If it is set to anything over the player's radius, it is automatically set back to the radius to prevent clipping, unless the radius is 0. ▸Player R: Player's radius. Used for collision. Set to 0 for no collision. 3D VIEW: ▸Fisheye: 0 means no fisheye, or in other words fixes the fisheye effect that comes naturally with all ray casters. 1 will actually give you that default fisheye effect (and also makes 360 FOV look a bit better). Have fun playing with extreme values! ▸Height Ratio: Adjusts how high the walls are drawn in 3D view. ▸Shading Number: (for lack of a better variable name) Affects how far you have to be for the shading to go black on a wall. Basically, if this is set to 100 (which I've found to be a good value for now), then when you are 100 units away from a texture, the brightness will decrease by 100%. Keep in mind that not all wall colors will have a default value of 100 brightness, for example, a 0000ff (blue) wall will turn black once it's brightness is decreased by 100%, however a 000080 (dark blue) wall will turn black once it's brightness is decreased by only 50%. 2D VIEW: ▸Grid Spacing: Grid size for 2D map. ▸Arrow Size: How big you want the player's arrow to show (There is a hidden variable that essentially multiplies the overall speed, which automatically gets set to 3 when loaded in Scratch, but set to normal 1 when loaded in Turbo Warp)

Project Details

Visibility
Visible
Comments
Enabled

More Cool Projects

Project thumbnail
View Project

BonziWORLD Ultra Revived

by jeremiahpls

Project thumbnail
View Project

Beat Up Martcallj! V0.5 / 8 Buttons

by KijobalKijobol5673

Project thumbnail
View Project

B (Russian Alphabet Lore)

by kossy897

Project thumbnail
View Project

Use the guest bathroom please #animation

by TylerBlu2103

Project thumbnail
View Project

Beat up Nano (0)

by ptv_23

Project thumbnail
View Project

MyTeardrop - BFDI - MID-ALPHA, [upcoming wardrob]

by KirbyPoyoooo

Project thumbnail
View Project

Wario Land "The Scratch Dimension" remix

by Elyusif07

Project thumbnail
View Project

Beat up Bonzi buddy remix remix remix remix remix remix remix remix remix remix remix remix r… remix

by bonzi346

Project thumbnail
View Project

Cprunki brud treatment

by darky2014

Project thumbnail
View Project

Spamton Neo fight normal edition

by Lemonlemonlemonie

Project thumbnail
View Project

雪合戦ゲーム  爆発地帯 戦争!!!!!

by Lisa_Panda

Project thumbnail
View Project

新・青の塔2階

by sakaryuu

Project thumbnail
View Project

Korokoro-kun world

by maluyuu

Project thumbnail
View Project

Warner Bros. Animation (2018)

by RoboXD

Project thumbnail
View Project

When I poop my pants...

by oransya123

Project thumbnail
View Project

This is Halloween AMV

by -WatermelonGum-

Project thumbnail
View Project

Sky Island (Original)

by DingoBingo1022

Project thumbnail
View Project

Geometry Dash Cursed Bonfire

by JohnDaTank

Project thumbnail
View Project

[☁online]オンライン サスケ2021 1stステージ プラットフォーマー online SASUKE platformer

by sikakitaharuki2

Project thumbnail
View Project

Life clicker | #Games

by NovaCodeMaster

Project thumbnail
View Project

SAUS Wheel

by MV42Channel

Project thumbnail
View Project

Shoot em' up Game remix hacked

by yura001

Project thumbnail
View Project

Halo ODST: Left Behind Mission 3

by daves777

Project thumbnail
View Project

Make your own BFB (team squares)

by beefyde26