Topic category: User side tutorials
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:
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.
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.
Then you just have to replace the number 3333 in the procedure with your gravity value (in my case, 0.25).
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:
Replace "motionY" with "fallDistance".
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!
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.
Very nice tutorial. Thanks.
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.
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
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
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
(I reuploaded because of an image glitch btw)