[TUTORIAL] Change the gravity (and air resistance)

Started by Mortimer Kerman on

Topic category: User side tutorials

Last seen on 10:47, 24. Oct 2022
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] Change the gravity (and air resistance)
Sun, 06/20/2021 - 09:43 (edited)

Hello, in this short tutorial, I will show you how to change the gravity of the player or an entity of your choice. It works in all versions of MCreator, although I made the images in 1.12. Small interface differences are therefore to be expected. First, you must add in a procedure of your choice which will have to launch on player update tick or of an entity of your choice (even a potion if you want) this code:

code

you can use any trigger conditions you want, for example detect if the player is on a custom dimension.

Firstly, you will need to choose the gravity. It can be stronger or weaker than normal gravity.

For this tutorial, I will use 25% of Earth's gravity.

Warning: If you put values lower than 4% of Earth's gravity, the player will be stuck in the air.

To calculate the gravity value, you need to calculate the percentage of 0.08 based on the gravity you want. In my case, I will therefore calculate 25% of 0.08, which gives me 0.02.

Replace the number 1111 in the procedure with your result.

code

Then you can change the air resistance if you want. You will therefore have to choose a number between 0 and 1. If you choose 0, the player will no longer be able to move vertically. If you choose 1, there will be no more friction, as if the player is in space.

Normal air resistance is 0.98.

For this tutorial, I will remove air resistance, so I choose 1.

Replace the number 2222 in the procedure with your value.

code

Then you just have to replace the number 3333 in the procedure with your gravity value (in my case, 0.25).

code

Now you can save and close the visual editor.

The last step will be to open the source code of the procedure and find this line:

code

Replace "motionY" with "fallDistance".

code

Now lock and save your code, and you can start the game!

https://i.imgur.com/dtDEfPu.mp4

And here is a gif of the result in game!

Enjoy!

Edited by Mortimer Kerman on Sun, 06/20/2021 - 09:43
Last seen on 06:31, 21. Jan 2024
Joined Aug 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
im gonna put this in some of…
Mon, 08/09/2021 - 21:37

im gonna put this in some of my mods dimensions now, thanks for the tutorial on this. didn't know I needed low gravity until now.

Last seen on 00:26, 25. Jul 2022
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Very nice tutorial. Thanks.
Mon, 07/25/2022 - 00:26

Very nice tutorial. Thanks.

Last seen on 18:17, 3. Jul 2023
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
1 - The code changed since…
Sat, 12/03/2022 - 19:09

1 - The code changed since your post so now I its no more MotionY, its getDeltaMovement or something like that. I dont know how to adapt the old method into the new code, I tried without success.

 

2 - Another thing is I would like to do the same thing you did on the Y axis but on X and Z too, to REALLY have no air friction and completely free movements in the air. I have my idea but cant think of a way to apply it (maybe im overthinking it).

My idea is to do the same with the Y axis but the player can go negative or positive direction so we need to detect that + there is no falling back naturally like with Y axis so the player would never stop if we add vector values so idk.

Last seen on 18:17, 3. Jul 2023
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay I managed to get your…
Sat, 12/03/2022 - 19:42

Okay I managed to get your method to work by changing brackets on the fallDistance part + removing the Y part after the original getDeltaMovement.

https://imgur.com/a/t4xM5Jp

Going to try to change X and Z air resistance

Last seen on 19:23, 7. Jan 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried this in 1.16.5…
Fri, 07/21/2023 - 02:24

I tried this in 1.16.5 mcreator and it works most of the time, but while flying you slowly float upwards, here's my code, can you help me? also, you can use custom code snippets to avoid editing the code in mcreator, since it resets when you open the blockly editormyCode

Last seen on 19:23, 7. Jan 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried this in 1.16.5…
Fri, 07/21/2023 - 02:33

I tried this in 1.16.5 mcreator and it works most of the time, but while flying you slowly float upwards, here's my code, can you help me? also, you can use custom code snippets to avoid editing the code in mcreator, since it resets when you open the blockly editor

https://ibb.co/0t6JDpP

Last seen on 19:23, 7. Jan 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(I reuploaded because of an…
Fri, 07/21/2023 - 02:34

(I reuploaded because of an image glitch btw)