Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I had the a very close problem once a while ago.
I don't know how movement in SDL works, but did you think about making a very basic collision handling? If you know the position, height and width of every object, in a very simple case you only have to check in the player movement routine if the next step collided with one of these objects. This should work and be only a couple of lines of code.
If you then wanted to optimise it, you could try to only check objects that are currently visible or near to the player. -
MrHallows656y@Benedikt Well, I keep thinking that it might partly be due to the placement of my movement/collision code within the codebase, too. The GameObject base class is structured with the HandleInput > Update > Render pattern and I guess I'm not exactly sure how to properly handle the code for input, movement and collision detection/resolution separately. In the hustle and bustle of trying to make it work, the "complexity" of the code tends to increase, but I always feel like it should be short, simple and succinct, but I just don't know how to execute it correctly. Do you know what I mean?
-
Hazarth95096y@MrHallows I dont know what you have, but you should have a World singleton somewhere (or passed in some kind of context). Or even a message passing/event system that lets the colliding object know what it collided with, and how far inside the other thing it is. After that you just need to pull it back by that much. This is trivial for circular and AABB collisions. Much harder for polygons, keep it simple for now as platforms dont need a super precise collision. Maybe if you can be more specific about your architecture and whats breaking I could help more.
-
pfs5366yWhat problems are you having exactly? I have some experience coding 2d platformer engines ;)
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
-
sam966911Hats off to this lady .... I would have just flipped the machine
So, I'm still not certain if it's actually a bug or merely my lack of experience, but I've been working on a 2D platformer game (using only C++ and SDL2) for roughly 2 years now (on and off; sometimes off for months) and I'm extremely embarrassed about this, but for the life of me, I cannot seem to get the player character's movement and collision physics working properly. It's driving me absolutely insane.
I've read articles and tutorials, referenced books, and posted about it in game development communities (e.g., gamedev.com, Discord servers, etc.), but even though the fundamental structure and explanations made sense, getting the code to work has been unsuccessful, albeit not completely so, but if I get one thing working, another thing breaks. It feels like I'm trying to repair a vase that fell off of a skyscraper and turned to dust on the street below.
I've always been a very tech savvy person with a fiery passion for programming, electronics and game/software/embedded/web development, but to be honest, having such a difficult time with things like this that — in theory, at least — seem like trivial bumps in the road have made me feel like I'm never going to be successful in this field. But regardless of the depressing thoughts of worthlessness, my passion doesn't let me stop trying. Who knows, maybe it'll have to remain just a hobby. 😕
rant
2d game
sdl2
game development
physics
collision
wk160
c++