Player Movement
Movement
Moving the player character left and right was originally done using Input.getkey and altering the Ridgedbody's velocity. However I ran into a problem where moving in the air would slow down the players decent. I later changed the code to use Vector2 to change the players x position and instead of using Input.getkey I used Input.GetAxisRaw. This way allows the frog to move left and right in its falling and gliding modes without slowing the fall.
Jumping
Using OnCollisionEnter2D and OnCollisionExit2D I've made it so the frog can only jump when in contact with an object with the "ground" tag as the frog could jump infinitely. These also change the frogs tag as when on the ground it has "Playerground" but when jumping it changes to "Playerair". I've implemented a jump which changes high based on how long the button is held for, using Time.deltaTime I can choose how long the jump button can be held in before the frog falls.
Gliding
The character will glide by increasing the drag on the player. This will be activated when the user presses the space key while in the air. Using a bool called isGlide and a line of code being isGlide = !isGlide the user can switch between falling and gliding as long as they are in the air. Other than switching the drag between 0 and 5 it also changes the frog's tags between "Playerglide" and "Playerair" which will be used later as the frog can only ride the wind in glide mode.
Tags
"Playerground", "Playerair" and "Playerglide" are the three tags the player character switches between. Later in development when wind tunnels are added the frog will only be able to ride them when the "Playerglide" tag is active. Looking at the code as it is now I might merge the ground and air tags as they aren't affected by any special mechanics.
It's Raining Frog!!!
Status | In development |
Author | LooperHoop |
Genre | Platformer |
More posts
- Documentation + User Guide31 days ago
- Updates31 days ago
- User interface31 days ago
- Presentation31 days ago
- Enemy and Interactions31 days ago
- Levels31 days ago
- It's Raining Frog! concept74 days ago
Leave a comment
Log in with itch.io to leave a comment.