/r/howdidtheycodeit

Photograph via snooOG

"Wow, how did they do THAT?" - Ask here, get enlightened!

This subreddit is for beginner/intermediate programmers to ask about how a specific feature in a game (or other program) was coded, if they can't imagine themselves how they would go about doing it. Answers do not actually have to be what the game was actually coded with, but can explain another method of accomplishing it.

We have user and post flair! If you want to see some other categories, let us know!

Question: Add this tag to your questions!

Answered: Question = > Answer

Showcase: Use this to tag your write-ups of your own features that make people say "wow, how'd they code that?"

Article: Use this tag for shared videos and articles that describe how a feature is done

Submission Guidelines

  • Be descriptive! It's hard to guess how something was made without knowing what exactly the feature/algorithm is. Try including screenshots and/or links to gameplay if possible.
  • Collaboration is encouraged! It's okay if you don't have any idea, but writing down your thoughts in the question will help give other redditors a jumping-off point.
  • One size does not fit all! When writing your questions and answers, be up front about the tradeoffs you're considering. Memory or Processing time? Visual fidelity or Texture Budget? Small Indie Game or AAA Studio?

(These are just suggestions, you can post without all of these, but the conversation will be more lively with a little bit of forethought!)

I created this subreddit because I am a novice coder who has often asked the question to myself when playing even small, indie games how a certain thing was coded. The thing that actually prompted me to actually create the subreddit though was a random, cool game, a Ludum Dare winner, Tangent: I was confused about how the circular transitions between different rooms of the game was accomplished. Example post about Tangent

/r/howdidtheycodeit

38,195 Subscribers

4

How they did this vfx?

https://x.com/_1mposter/status/1854283366440313258

They took a 3D model and made look like it was ASCII art but how?

5 Comments
2024/11/07
15:03 UTC

13

How did they implement the "whoosh" SFX in Need For Speed games

I'm curious how did they implement the "whoosh"/"doppler" sound effect in "Need for Speed" games when you quickly drive past an object. For example in Need for Speed, notice the wind sound when the car drives past lamp posts, columns and such (sorry for long videos - see timestamps). I'm especially curious how they handled tunnels as it sounds really good and is exactly for what I'm after:

I'm thinking that they did a sphere physics query centered on the camera to check for an entered object, then they noted the object size and car velocity. Given these parameters they then adjusted the pitch/volume and relayed the audio effect at the query intersection point.

Having said this, I made a quick prototype to test this in Unity:

  • I have a trigger around my camera.
  • The trigger tests for my target objects which should emit the "whoosh" SFX.
  • Once an object enters the trigger, I find the intersection point and position the sound effect at that point.
  • I then tweak the volume and pitch based on the estimate size of the object and player velocity.
  • Finally, I add some reverb to the audio effect and also enable doppler (I'm doing this in FMOD).

This approach works decently for small-ish objects, however if I'm roaming around a large object with lots of extrusions, my approach fails as I'm colliding with same object and my trigger doesn't fire multiple times. Additionally, it doesn't sound right in enclosed areas such as tunnels/caves or generally when surrounded by large objects. There must be some more complex system taking place here 🤔

Edit - found a possible way, here's my prototype which simulates this:

Example

Technical details

  • I fire 4 raycasts from the camera.
  • Once a raycast hits an object, I place an audio source at that point.
  • If the raycast continues to hit an object, the audio source follows the updated hit point.
  • If the raycast fails, I leave the audio source at the last known hit position and stop the loop, in FMOD I made it so that the audio effect smoothly decays in about 2s to avoid rough cuts.
  • The audio source has a doppler effect applied to it, which means that once the raycast fails and the source stays at a fixed position - this allows doppler to take action.
  • This kinda works for tunnels/caves, however it doesn't sound the same as in the NFS example - I think as u/TheSkiGeek mentioned, this needs an additional, manually placed trigger or some other faked system.
  • Finally, I use pooling for the audio sources - I only play audio sources if they are fully stopped, I found that this prevents audio artifacts.
8 Comments
2024/11/07
14:47 UTC

0

Movement

how do you code the movements in 2d games like champion island or stardew valley. specifically in godot

6 Comments
2024/11/04
05:47 UTC

0

How are there so many AI-based apps nowadays? Do they pay API calls for known LLMs or do they run their own AI servers?

12 Comments
2024/11/01
22:21 UTC

3

How duckduckgo's email forwarder works

I've been seeing <username>@duck.com emails
What I wanna do is build similar for my custom domain which forwards email to my gmail address
What tools and tech is required.
About me: I'm a webdev (intermediate level) I understand frontend and backend.
Please guide me, Thanks. :)

5 Comments
2024/10/31
12:10 UTC

2

MyMind

I want to make an app like MyMind and, on top of that, also create graphical nodes (similar to Obsidian). How would one go about coding something like that? Since I know JS/TS, I'm looking into using ElectronJS for this.

1 Comment
2024/10/30
11:04 UTC

3

Valheim's Rotating Build Pieces

Hi folks. I've always love the build system in Valheim and have just started about implementing something similar myself.

To my question: Do they have separate versions of each build piece at each possible rotation? (or at least many, not including reflections).

I ask this because the length of a 1 meter beam's length needs to change as it's rotated to make sure it ends at the correct spot on the underlying grid layout. Damn you Pythagoras and your Hypotenuse!

If they don't do that, do they scale the piece along its length depending on it's angle. Are they then mapping a new texture onto it or stretching the texture too because I can't say I've ever noticed the texture stretching as I rotate a piece.

Thanks in advance.

5 Comments
2024/10/28
12:03 UTC

6

How do large scale apps handle eventual consistency?

How do large scale apps like discord, Instagram, etc handle eventual consistency? I'm sure the database they use in the backend is sharded and replicated throughout several regions and each one needs to be in sync with the other. One of the best apps I see that does it flawlessly is Discord. On the other hand, reddit is one of the worst. Sometimes when I send a chat in reddit, it doesn't show up when I open the chat again for a while.

I know these apps also give the illusion of sending the messages by using optimistic updates but I am still wondering what exactly the frameworks, tools, languages are used to handles this. Especially with the extremely large volume of data

1 Comment
2024/10/27
17:55 UTC

11

I need advice for not so simple cubes

I'm making a game in Unity in where the player can build objects in a voxel style made of cubes. Objects like this L shaped you can see in this image:

https://preview.redd.it/oph51bg5d9xd1.png?width=454&format=png&auto=webp&s=565b9618b4708a7af50c8240969ac168869949dd

But the player has complete freedom to build anything you can imagine:

https://preview.redd.it/mvybhraed9xd1.png?width=460&format=png&auto=webp&s=4c24bece6284a49e986b89c5a4c2bbf9b56e408b

So, my code is procedurally generating the meshes for these objects, one triangle at a time. Doing this is fairly simple if the game is limited to plain cubes.

The problem is that this is visually too much plain and not very attractive, so I'm planing change the cubes for a model a little more complex, that renders a little more detailed:

https://preview.redd.it/v1fsbu24e9xd1.png?width=535&format=png&auto=webp&s=7a338a836aebbf663d29f2715cb658533f1587e8

This is prettier but, given the triangles needed for this, generating this procedurally is way more complex:

https://preview.redd.it/h5jr712ie9xd1.png?width=527&format=png&auto=webp&s=acb313c886bd2cb1ce8dac45ccaf995c7c3c856c

https://preview.redd.it/8xyefukwe9xd1.png?width=517&format=png&auto=webp&s=8ac07f0ae5a87c299225eba817ad5a458250de81

I've tried diffenrent approaches:

  • Make the objects with separated cubes, but this feels cheap, I feels way better if the cubes blend together.
  • Render each cube in the object with a pregenerated mesh. To do this, I need a mesh for every possible combination of neighbour cubes. If every cube has 26 neighbours that can be on or off this leads to more that 60M different meshes. So I tried to reduce using rotations and simetries, and after a few calculations, I have still more that 60k unique meshes. So this is for now discarded too
  • So my last idea is to separate rounded edges, and faces, and calculate which one is needed for each position, and instantiate them separately, something like this image:

https://preview.redd.it/jppof5y6h9xd1.png?width=412&format=png&auto=webp&s=388705c3a10b4020da56f38dfa45f7ca3312659d

So, my question is, before starting to code a complex algorithm to implement this mode, do you have another idea on how to do this? or at least a good idea on how to implement the last concept?

Thanks!

9 Comments
2024/10/27
08:43 UTC

9

Shelter algorithms

Can anybody on here speak to fast algorithms for checking "shelter" in survival games?

Most survival games I have played do a pretty good job of it instantaneously and I'm just wondering what kind of approach is used because it seems like a tricky problem. Like it's not just a roof over your head, you have to be somewhat totally surrounded by walls, roofs, etc. I couldn't find any generic algorithms.

Looking for actual experience - not just guesses.

11 Comments
2024/10/22
01:21 UTC

0

The fact that this is even possible baffles me

7 Comments
2024/10/22
00:02 UTC

4

How videolite continue video playing in background?

The VideoLite app seems using a WkWebView or some other UIView to load the YouTube website. When the app is pushed to background, the video is still playing. There is a movie_player element on the page to play/pause the video. But explicitly calling playVideo() on the element after app is put to background is not working.

0 Comments
2024/10/21
13:06 UTC

35

How do you decompile video games just in general?

A lot of N64 games have gotten decompilations recently, and I have no idea how you even do that. Like if I wanted to try decompiling a game myself, how would I do it? Would I need an emulator for any part of it? Is it all just guesswork?

Not including tools that decompile games for you, like for example Game Maker or RPG Maker decompilers. Curious how people do it without access to anything of the sort.

Also related question: is decompiling even legal in the US? I know reverse engineering is, but does decompiling fall under those laws?

9 Comments
2024/10/20
16:27 UTC

0

Instant Transmission in SPARKING ZERO... this game's such a coding masterpiece it tangle my mind

6 Comments
2024/10/20
06:22 UTC

0

How do people code price comparison sites then find a way to actually format the data

14 Comments
2024/10/15
18:18 UTC

9

World Map in Final Fantasy

How did they achieve the “endless scrolling” world map that gives that globe type experience? e.g. when you reach the bottom of the map it wraps around back to the top.

11 Comments
2024/10/12
20:55 UTC

15

Red dead 2 loading screen

Hello! I don't know if this is the right place for this, but I always loved the effect of a developing photo the loading screens in red dead 2 have, and was wondering how I could replicate something similar? Is it a shader or an animation of some kind?

7 Comments
2024/10/12
15:47 UTC

31

Traffic Lights in GTA

I feel I’ve asked this some where on here but I’m having trouble finding it. So i had asked one of the developers of GTA 3 how cars knew to stop at stop lights. He explained that because traffic uses waypoints some of those points were marked if they were near the traffic lights. There were only two states All North and South lights were green or East and West points were green. Which made sense to me.

However my brain was trying to make sense of another element after this how are the actual traffic lights in sync with the node states. Because if you remove the actual traffic lights the traffic will still behave as if there is still management. Which makes it seem like the object and nodes are completely separate but are still in synch somehow. I was wondering how that was possible? Not a-lot of examples of this online from what I’ve seen and i didn’t want to bug him again so I decided to post here.

11 Comments
2024/10/08
15:15 UTC

3

Types on different variants of similar things

Apologies if this doesn't fit here, but I've seen really good feedback here before and hoping to get perspective on the "best practice" for this type of thing.

I've been working on small web game and have been running into this thing in multiple places where I'm unsure about typing with one larger and vague type or multiple smaller, but more specific types.

As an example:

In the game I have abilities for different skills. Initially I had one type for ability, but had to use optional keys for differences between different types of abilities (for example crafting ability would have keys ingredients and product for input and output, where as combat ability would have effects key for combat effects).

After a while I tried breaking abilities to multiple types, but then that had it's own issues. For example if I have variable like selectedAbility or activeAbility those could be of multiple different types leading to some issues.

Right now I'm wondering between following options.

Option 1, Original version, one type with optional keys. Would look something like this:

export type Ability = {
   id: AbilityId;
   name: string;
   skillId: SkillId;
   levelReq: number;
   xp: number;
   effects?: Effect[];
   itemPropertyReq?: ItemProperty[];
   product?: GameItem;
   ingredients?: ItemId[];
   cost?: number; };

Option 2, Separate abilities. Two examples:

export type AbilityCrafting = {
   id: CraftingAbilityId;
   name: string;
   skillId: SkillId;
   levelReq: number;
   xp: number;
   product: GameItem;
   ingredients?: ItemId[]; };

export type AbilityCombat = {
   id: CombatAbilityId;
   name: string;
   skillId: SkillId;
   levelReq: number;
   xp: number;
   effects: Effect[];
   itemPropertyReq?: number[];
   cost: number; };

Option 3, Some other option?

Any advice on how to move forward would be appreciated. This feels like a thing where some learning from others experience would be beneficial rather than finding out 3 months from now that I chose wrong and have to majorly refactor things.

6 Comments
2024/10/07
19:15 UTC

53

How to account for various status effects for an SRPG?

24 Comments
2024/10/06
10:05 UTC

3

How does mysql CLI prompt for password despite input redirection?

For example:

$ mysql -u root -p < script.sql
Enter password:

how can it still access STDIN? wont stdin be replaced by script.sql?

3 Comments
2024/10/05
06:23 UTC

2

Starfield Entangled Mission

I'm curious if there is any non obvious way to code something that is essentially the same map but switching between universes/dimensions? Starfield had an awesome mission where you are navigating a ship stuck between two realities.

Is it always going to be just having two versions of the map player essentially teleports between? Or is there a way to reduce size of a level/scene by doing it in a layered fashion(say with clever viewport manipulation?). I dabble in programming and game engines so not very experienced, more curious than anything.

4 Comments
2024/10/04
20:47 UTC

4

Real time device tracking like Uber

I have a food delivery app that I am making in NodeJS, Express and React Native. I am trying to implement a mechanism where when an order is placed, a rider is assigned an order and then the user (who placed the order) can track the rider.

How would I go about doing this where I can assign a rider (based on their location whoever is nearest to the restaurant) and then the user can track in real time?

2 Comments
2024/10/03
06:38 UTC

16

What is considered coding a "physics engine"

This has to do with semantics and terms more than anything. I want to code simple collision detection and resolution, with intention not being realism. Is the term "physics engine" meant for specifically handling "realistic" physics? What would the term be for a simpler handling system? How would I go about that?

13 Comments
2024/10/02
20:13 UTC

3

How did they code the autonomous Vision part of this system (6 DoF Pose estimation)

https://youtu.be/yfQnEhrgs-A?si=RN_efXfCMngStIAQ

I've been really interested in SLAM systems and more particularly pose estimation for the past few weeks and I've found out that NASA and some aerospace companies have been doing it since 7-10 years (without the breakthroughs of AI and on minimal hardware).

So how did they do it without AI ? I tried some experiments with feature matching + PnP (with the hypothesis that I know the target's 3D model and my camera intrinsics) but the results are't that great because of the poor feature matching (I tried RANSAC with ORB/SIFT and still not good enough).

I wanna do it without using AI, just using cameras and 3D models and geometry.. my next exploration is using multiple cameras + triangulation techniques but I'm open to suggestions, if anybody have done this before please give me some roads to explore.. right now I created a scene in unity with a flying camera and a chased small airplane + some background objects to mess with the algorithm, I have the ground truth data thanks to unity reference frames system but I'm stuck in the algorithm that interprets the image, and I don't want AI because I'm not much of a fan if blackboxes and training for hours to get perfect weights ... I want something controllable with pure geometry and maths.

1 Comment
2024/09/30
22:02 UTC

15

How does Obsidian create these graphs?

https://preview.redd.it/31msr75wgyrd1.jpg?width=726&format=pjpg&auto=webp&s=3b02abd17e2c8294be19fedeeb8418861f427a86

How does Obsidian create these graphs? I want to make an app in Typescript, React/Next etc that is able to do something similar.

5 Comments
2024/09/30
14:20 UTC

4

How does the motion capture work on eyetoy/kinect?

I've been scouring the internet for info on this topic, i was hoping to combine it with the recent advancements in webcam based motion capture, currently used for mo-cap animation in the indie scene. Though i haven't had much luck as to how and what i should research to code it myself.

if anyone has experience or has links where i can read up on it, it would be greatly appreciated.

12 Comments
2024/09/29
12:14 UTC

1

How did they code the drift in sonic riders?

https://www.youtube.com/watch?v=VbDEvvfdd0E&t=60s at 0:42

I've found tutorials on how to program a drifting mechanic, but the one in mind to implement in my project is how it works in Sonic Riders, where you hold the button and choose your release angle then when you release th button you get a burst of speed in that direction.

Drift Drawing

I drew this quickly to best describe what I'm talking about:

1 Comment
2024/09/27
22:01 UTC

1

The search function of devdocs.io

I'm not a tech person but I have a project in mind that has a catalog of thousands of items and I want to use this kind of search functionality.

What tools are used for this dynamic search used by devdocs.io?

Thanks!

0 Comments
2024/09/27
10:33 UTC

Back To Top