Help with Physics

For the people who need to make a game with physics and turn out not to know… For starters, I need help with this. Anyone available?

5 Likes

Leader you can depreciate this topic at the end if you want to.

3 Likes

*typo: it’s “deprecate”.

3 Likes

It auto-corrected…

3 Likes

How ironic, lol.

3 Likes

I can’t edit…

2 Likes

I know. You’re past the 30m editing window. You can ask a leader to edit it for you.

3 Likes

Hmmm it’s fine… Anyways you know gravity physics don’t you?

2 Likes

For like platformers? @CodeHelp? Would anyone be fascinated helping me?

7 Likes

I would suggest looking at Spy Guys platformers, to get a basics

3 Likes

I don’t get it that way… blushes…

3 Likes

So I guess @Spy_Guy_96? Help?

5 Likes

So a basic platformer is made out of 2 parts.
The player and tiles. (And some other things but these are not important right now)

The player is where all the physics happen, the tiles is where the collision happens.

However, for the collision code to work properly, the player physics need to work properly.

So the player physics code have 3 sets of variables. 1 set of variable tracks the players speed (or how fast the player is going).

Another set of variables tracks the players current position (where the player is on screen)

And the last set of variables track the players Next position (where the player is going).

There is also the “air” variable which checks if the player is on the ground or not (if they are not, the player can’t jump.)

You also have scrolling but that’s not important right now.

The collision code is a bit more complicated.

Each tile calculates collision between the player and itself.

For a basic solid tile, there are 2 collisions. 1 for horizontal collision (walls) and 1 for vertical collisions (floor and ceiling).

If a tile detects a collision, it will change the variables that track the players NEXT position.

Say, if the player walks into a wall, the code will basically set the players next X position to be right next to that wall.

If the player jumps on a platforms, it will change the players next Y position to be on top of that platform (it will also set the variable “air” to 1 to show that the player is on top of a platform).

So that’s basically how it works without going to deep into the code. If you want to see how the code would look like, you can go into this project.

8 Likes

Thanks so much!

2 Likes

O yhea by the way, there currently is a bug in hopscotch that makes this code not work on newer projects so you might want to wait before starting your own.

3 Likes

Oh okay! Got it! Thanks like sooooooooo much!

(I can’t explain how much appreciate this!)

2 Likes

@FRENCH_WAVE123 clivecate pls, it seems this has been solved.

1 Like