I have a problem for a 2D platform game I’m trying to make. It’s my first real platform game and I’m trying to make it really good so I’m being really picky about it, or at least some people might say so. My problem lies within the platforms in the game. I am trying to make it so that the character can fall at a constantly increasing speed and still land on any platform beneath them without going through it or sinking into it for one frame before popping up to the correct height. How I did this at first was I had each platform check the _y distance between the character and the platform, if the distance between the character and the platform is less than or equal to the distance the character will go down in the next frame then it tells the character to go to the same height as the platform and basically land. So now I have all that king fine but I feel I have to rethink it because I want all the items and enemies to be able to interact with the platforms as well, in which case I would have to duplicate that same code over and over except with different instance names for the different objects and enemies etc. I think the solution I am looking for to cut down on massive amounts of repetitive code is to put the landing-on-platforms code inside the objects themselves that are landing on the platforms instead of in the platforms so that the objects are self-sufficient so-to-speak. One obvious solution would be to say the same thing except reversed: so that instead of “if that object is gonna touch or go past the this platform, then land ON this platform.” say inside the objects “if this object is gonna touch or go past that platform, then land ON that platform.” But this in turn would require saying that same code over and over to address every instance of the platform that are on the screen to land on. So summarized, is there any way that I can say something more along the lines of “if this is going to pass any platform then stop on that platform” so that I have one short sweet line of code in each object???
I’ll be watching the thread closely of course so just ask anything you dont get and ill explain thnx