Springs
In this tutorial you will learn how to make your character bounce off of springs.
Summary
Download Example
Before you Start
You will need the following:
- Platform game engine which includes a character that is pulled down by gravity and a wall.
- Spring Board Sprite, download mine, here
If you don't have this, follow this tutorial or download the example, Platform Movement
You need to create a spring object,
- Add a New Object
- Set the name as o_spring
- Set the sprite as your spring sprite
We only want the character to bounce when certain requirements are met.
The Spring MUST be below the Character and the Character must be falling down before bouncing. This will prevent a character jumping under a spring and getting a double height jump without properly bouncing.
- Open the Character Object
- Add a Collision Event with the Spring Object
First, we want to check that the spring is below the character when they collide.
- Add the, If There's an Object at Position from the Control Tab
- Set Y as, 1
- Tick Relative
This will check the position below the character to see there is a spring. If it is, the first condition is met, the Character is above the spring, now, we want to check that the character is falling, this is done by checking the vspeed to see if it's value is larger than 0, a number larger than zero is down because moving down on the Y axis is a positive number such as, 8.
- Add the, If Variable is a Value Action from the Control Tab
- Set Variable as, vspeed, because this is what we want to check
- Set Value as, 0
- Set Operation as, Larger than, because we want to check vspeed is Larger Than 0
If the vspeed of the character is larger than the zero, both conditions are true, if the character isn't above the spring, the vspeed won't be checked meaning the bounce action won't run either. It will only run if both are correct.
Now to make the character bounce.
- Add the, Set Vspeed Action from the Move Tab
- Set vspeed as, -12