This is an experiment of making a character move uphill, and act accordingly to gravity, so even though this project uses WASD keys, only the D key will work.
*PLEASE READ IF YOU ARE GOING TO USE THE CODE* I am considering making these tutorials into a series for beginners, so if you like this and want more, please heart it, and if I get 5 hearts I will start a series from this. This project is experimental, and if it works, is a tutorial for beginners. It is a demonstration of how to make a character fall accordingly to gravity, and move up a hill. If you would like, you can copy the code and use it for your own purposes, but I do encourage you to read the text below to understand how this works, so that you can customise the code given to your liking, and use this knowledge to help explore and understand other concepts. How it works: On the shorter script, all that’s happening is when the d key is pressed, the character will move an amount in a direction, (for the experiments purposes, the direction is up the hill, and in this example the amount is 5) In the second and larger script: I have added the starting point of the character, so that when the code has begun the character will return to that spot, then the next parts will be repeated infinitely. The character is checked for it touching the hill. If it isn’t, the character moves down a bit, as you would with gravity. If it is, the character moves up a little, and then it will check if the character still is touching the hill. If it is, nothing happens. If not, the character moves down once again to where it started. This last part, about the character moving up and down really quickly (too fast to see on screen) is necessary, because it the character is pressing d while touching the hill, (walking) and the character moves upward a tiny bit onto higher land, and checks if it is still touching the hill, (which it is, because it just moved a little bit up the hill) it won’t move back down again. That means that the character has moved uphill. Without this, when the character moves sideways, nothing is telling it to move up, and the character will simply move into the hill. Problems: If the character is inside the hill, then due to the coding, it will resurface. To get the character to move easier, I rotated it, and adapted the skin, so that ‘steps’ go upward instead of forward. This may interfere with some other code that may rotate the character back to normal. You can fix this by not rotating your character in the first place, and instead of using steps to go up and down, the character can move up and down using the Y axis. If somebody playing your projects has a slow devise, they may be able to see the character rapidly moving up and down. You can fix this by finding another way of sensing if the character has to move uphill. Credits to Choco-Doggo and , who I posted this in their fan club studio. Go check them out! Tags: to Thank you! (: