A Perfect Custom Platform Movement
Author: | Klikmaster
|
Submitted: | 17th July, 2003
|
Views: | 8291
| Rated: |
|
|
I've just learnt how to use the fastloop object, and I have come up with a use for it. It can be used to make a really good custom platform movement, although it would probably work for any movement.
Why use Fastloop?
Basically, when using detectors, and where you change the Y co-ordinates of a player to move it, the player will sometimes go below the floor because it skips 5 pixels or so in the movement, to prevent this, we must not change the players x or y values by more than 1 pixel each time, but maintaining the speed you want. Because fastloop repeats an event many times in one go, we can move the player one pixel each time, but instantaneously, For example, if we want the player to fall quite fast we make the player move down one pixel on every loop for 5 loops. This way the player will stop EXACTLY on top of the platform and not get stuck in it.
Now, I used value A of the player as the X-movement, and B as the Y-movement.
+ Every 00-05
+ Bottom detector is not overlapping a backdrop
- Add 1 to value B
/// This adds 1 to the players value B when it is not on the ground \\\
+ Value B > 0
- Start loop gravity Value B times
/// This means that when the players value B is greater than 0, start the gravity loop as many times as the value B \\\
+ On loop gravity
- Set Y coordinate to Y coordinate - 1
- Set position of bottom detector to...
/// This means that for every loop the player moves down 1. Also, here I put the positions of the bottom detector. This means that the detector wont be slightly behind the player, but it will ALWAYS be just below the player. \\\
+ On loop gravity
+ Bottom detector is overlapping a backdrop
- Stop loop gravity
- Set value B to 0
/// This means that when the player collides with the floor, the loop stops, notice that the player will stop EXACTLY on top of the platform. \\\
That concludes the gravity part. The same principles can be used to make a jump.
+ Upon pressing button 1
+ Detector is overlapping backdrop
- set value B to -5
/// When you press button 1, whilst on the ground value B will be set to -5. Nothing will happen with just this event because the gravity loop only works when the value is greater than 0 \\\
+ Value B < 0
- Start loop jump Value B * -1 times
/// This will start the jump loop, when value B < 0 (when shift is pressed). The *-1 will convert the negative value to a positive value because you cannot have minus loops. \\\
+ On loop jump
- Set Y of player to Y of player - 1
/// this will make the player move up 1 pixel \\\
+ On loop jump
+ Value B = 0
- Stop loop jump
/// This ends the loop at the top of the jump.
I hope you understand, but if you don't here is an open-source answer to your problems. It also includes an X-movement too. It uses the inbuilt fastloop in MMF, so it may only work for MMF 1.5 users. Its a cca file.
http://www21.brinkster.com/klikmaster/custom_platform_engine.zip
Save target as...
Hope you enjoyed, Klikmaster
Website: http://www.create-games.com/link.asp?id=847
|
|
|