Hacker News new | past | comments | ask | show | jobs | submit login
A first-person engine in 265 lines (2014) (playfuljs.com)
213 points by WoodenChair on March 13, 2019 | hide | past | favorite | 29 comments



I believe this is the smallest application of the concept I've seen, using only 128 bytes of binary: https://news.ycombinator.com/item?id=16538367

For example, raycasts run in constant time, so you can load up a massive world and it will just work, without optimization, as quickly as a tiny world.

If someone has some more time to try this out, the layer images of the 6502 processor here might make a good world to play around in: http://www.visual6502.org/images/6502/layers_index.html (that site appears down/intermittent currently, but archive.org has copies.)


That article is great - though (after looking at the shadertoy version https://www.shadertoy.com/view/MdXXz2) I didn't know that WebGL didn't have an XOR operation. Is that true? Does anyone know more about that?


Aah, this brings back memories of people writing raycasting engines in QBasic. That language was really not suited to this kind of thing, but people made it work! :D


I loved how much people made QBasic do that it wasn't suited for, part of what made the scene great :)


Drunk vision/walking:

  var i = 0, s;
  setInterval(function(){
    i+=0.02;
    s = Math.sin(i)
    camera.focalLength = 0.8 + s * 0.2;
    player.rotate(s * 0.02 - 0.01);
  }, 16);



Does this actually count as 3D?

I thought 2.5D was the term used for 2D assets used in a way to appear 3D.

Pardon my lack of familiarity with game engines if I miss-understood this.


2.5D is more of a retronym after the age of "full" 3D engines came to be. Before then, we'd call anything 3D that looked 3D, and the lines do certainly get blurred.

Wolfenstein 3D for example is practically a 2D game, you could redisplay it as a top-down shooter reminiscent of early 1980s games (much like the early Wolfenstein games, actually), and not lose anything. There is no Z axis in consideration for any game logic.

Doom, on the other hand, actually does have a Z axis, determining which floors can and cannot be reached, how they are displayed, whether projectiles hit enemies or not, and so forth. The (original) engine and map format don't allow any rooms-over-rooms though, so it is still considered 2.5D -- somewhere in between a 2D game and Quake.


I remember many of the isometric drawn/pre-rendered games with a fixed PoV (i.e. Zaxxon etc) being described as 2.5D back in the day. We knew they weren't exactly 3D but then again, they weren't your typical 2D platformer/side-scroller either. Battlezone was considered a 3D game back in its day so the rendering technology wasn't really the dividing line. It was more a question of if the game environment being navigated was 3D and if it had a reasonably realistic spatial representation on the screen.


Zaxxon was definitely 3D. You scrolled forward, could move side to side, and could also change height (and you had to, to avoid obstacles and shoot enemies)


To make things more confusing, 2.5D these days is also often used to describe (actually) 3D-rendered sidescrollers, like the New Super Mario Bros. games.


Indeed.

The term 2.5D has been obscured to the point that it no longer carries any useful meaning. We should all stop using it.

New Super Mario Bros is a 2D platformer with 3D graphics.


A "first person engine" could be ray-casting on a 2d map like the original Wolfenstein, or on a 2.5d map like the original Doom, or actual 3d like Quake and everything since. It's a broad term.

The fact it isn't called a 3d engine, to me as an old person who played Doom on its release, makes "first person engine" a more appropriate. name


FWIW Romero considers Doom to be 3D [0]. Although, that is with the choice of 2D or 3D.

[0] https://twitter.com/romero/status/826494127055466497


I thought 2.5D was used for 2-d rendered games that had depth, like zelda: a link to the past (very much a 2d game where you can jump down cliffs, but not climb up them).


That's not even 2.5D.

2.5D started with Doom and it refers to games where you can move on Z axis, but can never be at the same XY point at more than one Z. That is you can't walk under or over some other path.


The way sectors work in doom you can't have one floor above another (like a bridge), however, you can fan fall off a ledge.


Sure. You can’t get under the ledge though.

I don’t remember full details, but the gist of it was that Carmack optimized rendering algorithm around this specific restriction.


If only it could have been reduced by just nine lines.


Also compare this: https://lodev.org/cgtutor/raycasting.html

It's a bit old but also explains a lot of the underlying logic. And it's not written in javascript so it may be more readable to some.


I'm not convinced the complexity is really independent from the size of the map. With large emptyish maps the rays can travel a long distance before they hit something. And tracking the ray is linear wrt its length.


Complexity is proportional to the size of the view distance (linearly? Or square if you do a field of view). The map size doesn't matter, assuming array lookup is instant.


Agreed. It's linear in the average view distance per column, which has the map size as its upper bound. I guess you could make a case for the average view distance being independent of map size for a given map style.


I love this article since the first day I lay my eyes on it. The first time around I wasn't so much of good programmer to try and implement it myself, I now feel more confident, as soon as I get some time I'll get to it. I made a 3D version of a similar "game" some time ago using three.js, but it's not the same. I love those old graphics.


Pedantic correction: Daggerfall didn't use a raycaster, it was a full polygon engine (although with sprite characters).

Its predecessor Arena did appear to use one though.


Duke Nukem 3D didn't use raycasting, either [0].

0 - http://fabiensanglard.net/duke3d/build_engine_internals.php


Fantastic explanations & kudos for boiling this down to the bare essentials!


Should there be a 2014 tag?

Pretty cool article though!


Added. Thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: