147

I slightly disagree with Philipp's answer; or at least with how he presented it. It gives the impression that moving the world around the player might be a better idea; when it's the exact opposite. So here is my own answer... Both options can work, but it's generally a bad idea to "invert the physics" by moving the world around the player rather than the ...


89

Both options work. But if you want the endless runner to be truly endless, you will have to keep the player stationary and move the world. Otherwise you will eventually hit the limits of the variables you use to store the X-position. An integer would eventually overflow and a floating point variable would become increasingly less accurate which would make ...


48

There are three common ways games sort this out: Minimum Separation Vector Upon a collision, compute the shortest movement that pushes the bodies apart into a non-intersecting position. If I've crept just 0.1 units into the platform's left side, but my feet are 0.2 units below its top surface, then the shortest movement to resolve the penetration is to ...


41

I think you need to consider this at a more fundamental level: what is the gameplay purpose of having a health system in your game? A conventional health system serves two purposes: (1) it gives a staged failure state to combat, and (2) it serves to create long term resource management with health between fights. You say you want your game to be ...


37

Building off of XenoRo's answer, instead of the re-rooting method they describe, one could do the following: Create a circular buffer of parts of your infinite map generated, which your character moves through with position updated with modulo arithmetic (so you just run around the circular buffer). Start replacing parts of your buffer as soon as your ...


34

I think you'll have to take the box's movement into consideration. That is, only crush if the box is moving towards the player. This is similar to other problems in platformers, where the movement is important. E.g. for platforms that you can jump through and onto from below, don't check collision if the player is moving upwards. So a block can crush the ...


23

You don't need to adapt A* at all. The only consideration is where you put your nodes and how you connect them. The linked article seems to convert from a platformer-friendly model to a grid based pathfinding model, which I don't think you want. A* itself is a tree search algorithm which finds the optimal path through your graph and requires some heuristic ...


21

In various Super Mario games, it's called a pit, abyss or bottomless pit. Bottomless Pit is also a TV trope.


14

As already asked and accepted, it really depends on the scope and style of your game, but since it wasn't mentioned: FlappyBird moves the obstacle across the screen, rather than the player across the world. A spawner is instantiating objects off screen with a fixed speed in the Vector2.left direction.


12

You mentioned having thought about auto-regeneration and your issue with that was the possibility of a player, while in the middle of a fight, running around while they auto-regenerate health. Have you considered auto-regeneration only when not-in-combat (aka out-of-combat)? This is an approach taken in many games. You could combine this with one or more ...


11

In such cases, you may be better off letting the client be slightly authoritative. For such precise controls you're extremely unlikely to get good behavior even with really advanced correction and prediction. The client needs to extend from just sending "I jumped" messages to sending "I jumped from X,Y at time T" messages. The server then checks that the ...


11

There are three general approaches to dealing with stairs in video games: The "Mario" approach is that you must jump to get up stairs. The "Castlevania" approach is that moving up/down stairs is a different sort of movement; you must press 'up' on the controller, and a special "stair-climbing" animation is played to traverse the stairs. A variant of this ...


10

If you're able to rotate the boundingboxes, I would've put a 45 degree rotated box at the player's feet and combine it with one non-rotated box to represent the rest of the body. That could make the player automatically slide over anything small enough. Though, that would probably cause some clipping with the player model and the stairs. Another idea is to ...


9

No, you don't have to use any specific toolset and you don't have to use any specific (physics) library either. It's just a question of convenience, since things like Box2D will provide you other benefits as well, e.g. being able to do collision, physics simulation etc. If you're not using tiles, you'll most likely want to write your own custom editor. As ...


9

Have the "crush test" points be inside the gray box shown in your image #1 - i.e. kill the player only if you detect a hit on one of the pixels there.


7

Most games don't have a separate class for each level. The usual way is to store the layout of each level in a file. These map files contain the environment and the positions and properties of all objects in it. When a level starts, the map file is loaded and a Level object is initialized with the data from that file. When the player finishes the level, ...


7

You seem to have a handle on this already. My current 2D platformer has objects that implement different concerns, including the following: Notifiable - can be event-driven and scripted Collidable - can interact with solid tiles (eg NPCs) Intersectable - exists in 2D space and can intersect with the player (eg doors) Intersectable - exists ...


7

Make sure that there is a visual cue that the player is currently not in control. When it is a non-interactive cutscene, you could remove the GUI during the cutscene and bring it back as soon as the player is in control again. When the users control is impaired (but not completely disabled) during normal gameplay, for example because their character is ...


7

I'd recommend changing Input.GetKey("space") to Input.GetKeyDown("space"). This way the check is only performed on the initial key press, rather than every frame the spacebar is held. The other issue is at the bottom of your script: ableToJump = Physics2D.Linecast(... Since the physics step (aka fixed timestep) is only updating every 2 milliseconds (by ...


7

Perhaps you can add some non-conventional healing system. Like for example : Health steal -> percentage of health gained = percentage of enemy health lost, and varies with enemy level. Every nth hit -> every nth hit gains certain health with certain weapon/class/etc. Implement the common methods -> but minimal like 1-5% Think something like these, maybe ?


6

There are multiple ways to solve this. If you want to include said long drops and other one-way obstacles, that should be factored in possibly as a feature. The Legend of Zelda series often uses these to prevent the player from missing or giving up on important rooms of the dungeon. A simple solution is to allow the player to use an item they obtain later ...


6

This is an excellent question because you are experiencing a problem that's quite commonplace with less experienced programmers: attempting to solve your problem with a purely imperative approach. Luckily this problem has been encountered and solved by people much smarter than I, thanks to the mathematical concept of a finite state machine. A finite state ...


6

As someone who grew up with 80s platformers, my first comment is that the contact points must be exactly on the sprite, not anywhere outside it. There were few experiences more frustrating than dying when a weapon/crusher/enemy was clearly several pixels away from your character - and that kind of experience is what stops people playing. With that in mind, ...


6

There's lots of examples out there in 2D platforming, it's really a question of how you want healing to be "interesting"? I would agree with suggestions that "skillful" play should be rewarded, but also give the player enough opportunities to use resources and play strategically. A few thoughts: DeadCells uses a "flask" system where you fill up between ...


6

You have essentially 2 options. You can either apply a constantly decreasing force to the character while the player is pressing the space button and stop immediately when they release it or apply a higher force of gravity when the player releases the space and go back to normal gravity, when the jump reaches the peak. For instance, the first Super Mario ...


5

New Answer: Lets look at the image. The player (represented by a circle) can jump to the left or to the right. What makes the difference is how much time passes since the moment the play jumps until the moments she lands on another platform. If we randomize a direction, either left or right and a value for time t than we can place a platform in that ...


5

If I recall correctly, both Prince of Persia and Flashback (as well as its predecessor, Another World/Out of This World) only allowed movement in set 'steps': if the player ran or walked, they would move a predetermined amount of space (i.e. 8 pixels for a single step, or 32 pixels for a running stride). They were effectively tile-based, and the player's ...


5

1)Cast a set of rays from origin to the ground evenly distributed through the width of your object. 2)Draw your shadow as a small portions of black sprites with varying height so you can round the edges. Make sure width of a sprite portion is enough to cover distance between rays. 3)Tweak height of shadow sprite portions and make sure your shadow looks as ...


5

Most importantly: plan for remappable controls from the start. Different games use different conventions, and different players have different preferences. This is also important for accessibility - not everyone plays with the same hardware - electrically or biologically speaking - and the ability to remap controls can turn an impossible game into a ...


Only top voted, non community-wiki answers of a minimum length are eligible