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

Sonic Frenzy 3 And Knuckles V0.2 #Games #All

by nuttygamer27

Project thumbnail
View Project

fighting game: the first one

by WeirdDeer

Project thumbnail
View Project

[unoffical] Undertale Neutral Run Sans Fight!

by Tota83

Project thumbnail
View Project

My interactive Spanish Alphabet Lore!

by wario100

Project thumbnail
View Project

FNF - Dusttale Remastered

by chucky_lee

Project thumbnail
View Project

It's A Box Of... // #animations

by MrAK2006

Project thumbnail
View Project

ダダサバイバーver.2.s

by scratchegg1414

Project thumbnail
View Project

Starlight Noise

by Robostew

Project thumbnail
View Project

Da Pieces [sigma] 0.1.0 A One Piece game remix

by BumFasefIsaac

Project thumbnail
View Project

Wall Runner Ultimate (v1.1)

by theChAOTiC

Project thumbnail
View Project

Beat Up Evil Cussing Splaat remix remix remix

by kubakoodziejczak

Project thumbnail
View Project

yfm gen 1.5 vectors

by sussymanamongus

Project thumbnail
View Project

✿ Icon Creator ✿

by SophIIsa

Project thumbnail
View Project

no players online

by mikailabidzar

Project thumbnail
View Project

Harry Interactive Russian Alphabet Lore 1.2

by Binary-Pete

Project thumbnail
View Project

Added Uppercase Hamilton, Izzy, Ivy, Joey and Ken

by Pikachufanatic2020

Project thumbnail
View Project

{リメイク}にゃんこ大戦争基本キャラクター中心の素材

by haruto_mario

Project thumbnail
View Project

Timeblocks Band 16

by SharkyBlues3rd

Project thumbnail
View Project

BasketBall!!! NEW SHOT METER #BasketBall #Games #trending #art #music #all

by Switch4FortNite

Project thumbnail
View Project

A nano gets grounded episode, but it’s pure laziness

by hot655

Project thumbnail
View Project

東方地霊殿 〜 Subterranean Animism. Extra Reimu A

by Rikipoyo0821

Project thumbnail
View Project

Portal Scratch Edition 1.7

by _The_Gamer_Man_

Project thumbnail
View Project

Windows 11 #OS (WIP)

by scratch-user-18473

Project thumbnail
View Project

Pet Collector

by G4L_LePro576_