r/howdidtheycodeit • • Jan 30 '20

Question How did they code that you can walk in front and behind this sprite? Is it a 3D plane?

Post image
119 Upvotes

r/howdidtheycodeit • • May 29 '20

Tactical game map generation (demo and source in comments)

118 Upvotes

r/howdidtheycodeit • • Mar 09 '20

Article We made a parallax effect inspired by Hearthstone! (Full video in comments)

118 Upvotes

r/howdidtheycodeit • • Jul 27 '22

How would you code a camera lens, or shader to create this effect?

Post image
117 Upvotes

r/howdidtheycodeit • • Dec 24 '19

How did Minecraft make procedural terrain

108 Upvotes

Problem

Hi. I'm trying to make a voxel game in c++/opengl with procedurally generated terrain using 2d Perlin noise and I've ran into a problem. I generate the world in chunks. The chunks have the kind of properties I'm looking for but between the chunks there is no coherence at all. This is the first time I have worked with noise so my implementation is... well it doesn't work like it should. I first make random gradient vectors for each cell/chunk (ranging between [-1,1]) and then calculate the difference vectors(vector components ranging from [0,1]) then get the dot product of the diff and grad vectors, and finally interpolate between the 4 dot products with c^2 continuity, but even tho the gradient vectors are shared between cells/chunks that are side by side to each other as described in the first pic:https://imgur.com/a/ryyw4x1 there is no smooth transition between cells.

Also I disabled textures and render with pre-baked fragment colors in the vertex buffer so it may look a bit ugly from the video. My code also may not be the cleanest or most readable so sorry for that. If you could help finding the error it would be appreciated. Thanks.

Here is the code:

#pragma once
#include <glm/gtx/transform.hpp>

class PerlinNoise2d {
    public:

        PerlinNoise2d(unsigned short height , unsigned short width , const unsigned short gridsize );
        ~PerlinNoise2d();
        float GetNoise(unsigned short x , unsigned short z);
        void NewNoise();

    private:
        glm::vec2** gradient = nullptr;
        float** noise = nullptr;
        unsigned short height;
        unsigned short width;
        unsigned short gridsize;

        float Sample(float x , float z , glm::vec2* grad);
        float f(float t);
        float Mix(float x , float z , float a);
};
#include <noise.h>
#include <iostream>

PerlinNoise2d::PerlinNoise2d(unsigned short h , unsigned short w , const unsigned short g ) {
    height = h;
    width = w;
    gridsize = g;
    gradient = new glm::vec2*[g];

    for(int i = 0 ; i < g ; i++) {
        gradient[i] = new glm::vec2[g];
    }

    noise = new float*[h];
    for(int i = 0 ; i < h ; i++) {
        noise[i] = new float[w];
    }

    NewNoise();
}

PerlinNoise2d::~PerlinNoise2d() {
    if(gradient!=nullptr) {
        for(int i = 0 ; i < gridsize ;i++) {
            delete[] gradient[i];
        }
        delete[] gradient;
    }
    if(noise!=nullptr) {
        for(int i = 0 ; i < height ; i++) {
            delete[] noise[i];
        }
        delete[] noise;
    }
}

void PerlinNoise2d::NewNoise() {

    for(int k = 0 ; k < gridsize ; k++) {
        for(int i = 0 ; i < gridsize; i++) {
            gradient[k][i][0] = ((float)(2 * random())/(float)RAND_MAX)-1;
            gradient[k][i][1] = ((float)(2 * random())/(float)RAND_MAX)-1;
        }
    }


    float localx = height/(gridsize -1);
    float localz = width/(gridsize -1);
    glm::vec2 tmp[4];
            
    for(int n = 0 ; n < gridsize-1 ; n++) {
        for(int j = 0 ; j < gridsize-1 ; j++) {

            tmp[0] = gradient[n][j];
            tmp[1] = gradient[n][j+1];
            tmp[2] = gradient[n+1][j];
            tmp[3] = gradient[n+1][j+1];

           
            for(int i = 0 ; i < localx ; i++) {
                for(int k = 0 ; k < localz ; k++) {
                    noise[n * (int)localx + i][j * (int)localz + k ] = Sample( (float)i / localx , (float)k / localz , tmp) / (float)2;
                }
            }
        }
    }
}

    

float PerlinNoise2d::Sample(float x , float z , glm::vec2* grad) {
    
    glm::vec2 differencevectors[4];
    float dots[4];

    differencevectors[0][0] =   x;
    differencevectors[0][1] =   z;
    differencevectors[1][0] = - x;
    differencevectors[1][1] =   z;
    differencevectors[2][0] =   x;
    differencevectors[2][1] = - z;
    differencevectors[3][0] = - x;
    differencevectors[3][1] = - z;

    dots[0] = glm::dot(differencevectors[0] , grad[0]);
    dots[1] = glm::dot(differencevectors[1] , grad[1]);
    dots[2] = glm::dot(differencevectors[2] , grad[2]);
    dots[3] = glm::dot(differencevectors[3] , grad[3]);

    return (Mix( Mix(dots[0] , dots[1] , f(x) ),Mix(dots[2] , dots[3] , f(x) ) , f(z) ) );
}

float PerlinNoise2d::GetNoise(unsigned short x , unsigned short z) {
    return noise[x][z];
}

float PerlinNoise2d::f(float t) {
    return t*t*t * (t * (6.0*t - 15.0) + 10.0);
}

float PerlinNoise2d::Mix(float x , float z , float a) {
    return ((1 - a) * x ) + (a * z);
}

r/howdidtheycodeit • • Aug 29 '22

Question How do they code those AI that learn how to play a game ?

106 Upvotes

Recently I have been watching this guy and I really enjoy his videos, but I am more curious of how he makes the AI learn how to play the game, with the generations and the network and all that stuff. He doesn't say how he does this, he only shows how he recreates the game.

Any ideas ? Thank you !


r/howdidtheycodeit • • Aug 16 '20

Question Worlds Adrift - 3D Climbing System

105 Upvotes

r/howdidtheycodeit • • Dec 02 '19

Zelda's Toon Shader in Unity

Thumbnail
youtube.com
104 Upvotes

r/howdidtheycodeit • • Jun 05 '22

How did they code the factories and conveyor belts in factorio?

103 Upvotes

In general how would you go about coding a building that takes input and produces output. How would you code a conveyor belt that moves items?


r/howdidtheycodeit • • Nov 07 '19

How does Stan's jacket from Tales of Monkey Island work?

Thumbnail
youtube.com
102 Upvotes

r/howdidtheycodeit • • May 10 '21

Question In Star Citizen, major hub areas have "Armistice Zones" where all weapons are disabled. Some also have defensive-armament. In this clip, a player outside the zone is shooting in, triggering the armed-response. How might they implement detection of said-infractioms for this system?

99 Upvotes

r/howdidtheycodeit • • Jun 20 '26

Question How are the wavy edges between blocks/tiles done?

Thumbnail
gallery
98 Upvotes

In most block/voxel games, the same optimization is used for the world. The block data is grouped into chunks, and each chunk's data is used to generate a single mesh and texture, for performance reasons.

Generally though, and in games like Minecraft, this means the blocks surfaces are all perfect squares, with their edges being perfectly straight lines.

In Pokopia and Tomodachi Life, as shown in the provided pictures, the edges of the blocks have a wavy or jagged border when touching a different block.

How is this done?

Does this still utilize the pattern of converting block data into quads and then stitching them into a single mesh?

This system is also agnostic to specific block textures. There is no "grass to dirt border" texture. It's the same wavy edge for every block in the game, which makes me wonder if it's some shader magic or something, though I'm unsure how that would work, since there would be no intermediate vertices for a vertex shader to "warp" into a wavy edge.

Anyone have any clues?


r/howdidtheycodeit • • Jun 03 '25

Question What is the purpose of Docker?

98 Upvotes

I know it is to solve the "it works on my machine" issue. But the main advantage of docker over a virtual machine is that it is more lightweight. I was reading an article recently, and it said that the performance gain of docker is only true in Linux. When we run Docker on macOS, it uses Docker's own environment as a virtual machine. If it is on Windows, it must use WSL, which has overheads and utilizes Hyper-V, which is, again, effectively a VM. So the benefit is only there if we use docker in Linux? But that seems limiting since if I am developing in a linux environment, I could just as easily provision the same linux environment in AWS or any other cloud provider to ensure I have the same OS. Then for my application, I'll install the same dependencies/runtime which is not too hard. Why even use docker?

Also, what is the difference between Docker and tools like Nix? I know many companies are starting to use that.

EDIT: Link to the article I mentioned


r/howdidtheycodeit • • Mar 10 '20

Article We've created the Sub-Zero's Ice Ball in Unity (from Mortal Kombat 11) What you think about it? (Full video in comments)

98 Upvotes

r/howdidtheycodeit • • Jun 09 '22

How do games like Grand Theft Auto and Sims have modular clothing systems?

97 Upvotes

How do games with clothing options swap clothes, retain the animation and apply to new clothes, and how do they make it seamless?

I can kinda see like, a shirt mesh and a pants mesh that each only have torso and leg animations, respectively. But how do they make it so the top of the pants attaches to the bottom of the shirt and there's no gap when the player bends down?

Assuming it's one single player skeleton and not one for each clothing piece, how do they add the clothes and stick that portion to the whole skeleton?

The way I'm imagining it is a lot of choppy bits and pieces, but AAA games somehow make the custom clothing look like the character was animated with that specific shirt and pants together.

I can kinda wrap my head around the way they do faces, moving the points themselves around in the mesh data. Do they do that for clothes too, like warping the naked body mesh into clothing shapes and changing the skin texture to one with fabric included?

Even things like MakeHuman have this weird perfection when swapping out clothes, the way it deletes the skin underneath but somehow still never has visible gaps.


r/howdidtheycodeit • • Oct 27 '25

How did they code that you can walk in front and behind this sprite Is it a 3D plane

Post image
96 Upvotes

r/howdidtheycodeit • • Jul 06 '24

Question How do they code enemies jumping up and down elevation and across gaps to reach the player. You see it in so many games and I'm not sure how it works

95 Upvotes

r/howdidtheycodeit • • Jun 22 '22

How did they code Soul bar in Hollow Knight?

94 Upvotes

Hollow knight has a Soul bar that that shows if you can use your abilities or heal up. It's pretty nice since it looks like water with waves. My question is how it works that it has this wavy water effect? The bar has a circle shape so it's hard to use sprite animation there. In order for this to work you have to support different elevation levels. Did they make animations for each level? I think it's also possible to do some sprite scaling magic depending on the elevation. If that's the case it would be nice if someone explained it in detail.


r/howdidtheycodeit • • May 13 '20

Showcase I've tried recreating the basic gameplay from the Pikmin games!

Thumbnail
youtu.be
94 Upvotes

r/howdidtheycodeit • • Apr 24 '20

Recreating Noita's Sand Simulation in C and OpenGL | Game Engineering

Thumbnail
youtube.com
94 Upvotes

r/howdidtheycodeit • • Aug 15 '24

Question How did they code it: Dynamic smoke effects in Animal Well

93 Upvotes

r/howdidtheycodeit • • May 31 '23

How did they achieve this? Is it really Npc memory or is it some clever trick

Post image
92 Upvotes

r/howdidtheycodeit • • Mar 18 '20

Article [ICYMI ] We have created the "Wasted Effect" inspired by GTA. What do you think? Full tutorial in the comment

92 Upvotes

r/howdidtheycodeit • • Jun 14 '19

How Do We Improve It?

92 Upvotes

Hi ya'll, Mod Kernalphage here

I had a couple ideas for getting this subreddit going, and I wanted to know your opinions!

  • Weeklies / Monthlies?

    • I was thinking something like "Whitepaper Wednesdays", or "Monthly Challenge" where we can vote on a paper, screenshot, or feature that we could try and reproduce together.

  • Should I enable Spoilers?

    • /r/dailyprogrammer uses them to hide solutions and keep people from peeking at ideas before coming up with their own. I'm not sure if this would help innovation or hurt collaboration, though.

  • "How Did I Code It" posts? Showoff Sundays?

    • This could be for people to show off code features they're proud of, while providing source or explanations. Not quite tutorials, but for inspirations and jumping off points. I can't find a subreddit that features these kinds of posts (/r/truegamedev ? /r/generative and /r/creativecoding sometimes has them?), but I personally can't get enough of them.

If you have any ideas, I'd love to hear 'em!