Tutorial: Gravity without 2D Physics
-
removeable: yes I know that physics blocks exist but this is for users (like me) that don’t know how to use them.Does your gravity look like this?
Don’t you wish it could look like this without the use of 2D Physics blocks?
Well, I can show you how! First, you need to select a sprite!
I’ll choose a white squircle.Then you need a Level sprite! I will just use a square. Alright, let’s get to coding! First we need a
when green flag clicked
block!
Now we need a forever loop! It should look something like this:
We should make a Gravity variable, and don’t forget to start off with Gravity being 0!
Here’s what I did:
Now don’t forget to add collision!
This didn’t quite work. Let’s fix that!
Perfect! Now we need a key to press to start it! I’ll use Space Bar.
Uh oh! The player can jump indefinitely! Let’s fix that!
Good job! You just made basic, but customizable Gravity!
It’s a bit buggy, but it works! If you know how to fix some issues, please contact me by making a new topic with the title; “RE: Tutorial: Gravity without 2D Physics”, and you may tag me as well.I hope you found this tutorial useful, and I might make some more!
-
@106809nes oh cool, this is what you normally do in Scratch. Basically just gotta check forever if the player is not touching the ground. If not, you have to change y by a negative value like -0.5 until they are touching the ground. Good tutorial tho
-
@jeffreyrb03-gmail
Thanks! I do this a lot for quick and simple projects, but for big games like mine, I make usable, completely customizable, non-buggy gravity. -
-
-
-
-