The following was half made just for myself, and i wrote it in notepad. I just thought there might be some people out there who still dont understand why and how custom movement works. Hopefully this will change that.
If you already know how to then don't worry about reading it, but it might be worth a scan through.
|----------------------------|
|CREATED BY ZEPHNI ON 1/06/09| How to do custom platform movement with slopes
|----------------------------| (take note on event ordering, it matters)
-S E T T I N G U P-
____________________________________________________________________________________________________________________________
|LEVEL EDITOR
Create 1 square object (size depends on how big you want your player to be) called it "Player Body"
"Player Body" alterable values: "spd","jump str","gravity","horizontal","vertical","On ground bool","Cur jump","extra jumps"
Create 3 objects 1 pixel high and width = to "Player Body" call them "Floor Detector","On Floor Detector" and "Head Detector"
Create 2 objects 1 pixel width and height just 1 pixel less than "Player Body" call them "Left Detector" and "Right Detector""
Create 1 object that is 1 pixel in size, call it "Slope Detector"
(i would recomend color coding thease so you can debug easier)
_______
|objects|
________
| | You should now have:
|example:| "Player Body"
| | "Left Detector" , "Right Detector"
| _ | "On Floor Detector" , "Floor Detector" , "Head Detector"
| |o| | "Slope Detector"
| - |
| -. |
|________| [NOTE THAT ALL HOT SPOTS SHOULD BE AT THE UPERMOST LEFT PIXEL OF ALL YOUR OBJECTS!]
Now just create backdrop object/s that create a sensible testing ground.
Somthing like this:
_________
|play area|
_______________
|...............|
|_________......|
| |_....| Somthing that you can test collisions on:
|\_o_ |__ | Left & right
|....| ____|| Up & down
|....|____/.....| Slopes left & right
|_______________|
|EVENT EDITOR
Make a group called "normal movement"
Make a groups inside that called:
"X ctrl","X loops"
"Y ctrl","Y loops"
____________________________________________________________________________________________________________________________
|EVENT EDITOR
--------------------
- X C O N T R O L -
--------------------
Go into the group "X ctrl"
First set a event that runs everytime we start the application that sets contstants (like speed)
+ Run this event once
- set spd("Player Body") to *desired speed (i choose 2)*
Then we need to start taking in key presses.
Player holds right:
+ Repeat while joystick right
+ NEGATE: ("Right Detector") overlaping backdrop object
+ horizontal("Player Body") < spd("Player Body")
- set horizontal("player Body") to horizontal("Player Body") +1
Player holds left:
+ Repeat while joystick left
+ NEGATE: ("Left Detector") overlaping backdrop object
+ horizontal("Player Body") > 0-spd("Player Body")
- set horizontal("player Body") to horizontal("Player Body") -1
Now we make conditions depending on wether the player isnt pressing anything, and an action giving him deceleration to
eventualy come to a hault.
Player going right:
+ NEGATE: Repeat while joystick right
+ NEGATE: repeat while joystick left
+ horizontal("Player Body") > 0
- set horizontal("Player Body") to horizontal("Player Body") -1
Player going left:
+ NEGATE: Repeat while joystick right
+ NEGATE: repeat while joystick left
+ horizontal("Player Body") < 0
- set horizontal("Player Body") to horizontal("Player Body") +1
Now we are going to set the loops for our X movement, but first a quick look at somthing that your going to have to come
back to... (note you will have to set these positions in each loop condition. best way is to drag the event across,
just be carefull when your doing that)
_- D E T E C T O R P O S I T I O N S -_____________________________________________________________________________________
|NOTE: on every "Xmove" and "Ymove" loop you make you must state the positions of your detectors!
|Ok now would be a good place to note where all the detectors have to be positioned:
|(note that these are all positioned relative to the "Player Body" object.
|
|on floor detector: X position = 0 , Y position = height of "Player Body" + 1
|floor detector: X position = 0 , Y position = height of "Player Body"
|left detector: X position = 0 , Y position = 0
|right detector: X position = Width of "Player Body" , Y position = 0
|head detector: X position = 0 , Y position = 0
|slope detector: explained below:
|
|
|Now the slope detector is different. It depends wich way we are faceing on where we want it to be.
|The only time we choose its X position is whether we are going right or left.. So in the above bit of code we should put:
|
| - set X position("Slope Detector") to X position("Player Body") -1
|
|Then in the next bit of code we will put it to this:
|
| - set X position("Slope Detector") to X position("Player Body") + width of "Player Body" +1
|
|This is so the slope detector is always lagging 1 pixel behind the player. Now in all our "Ymove" & other "Xmove" loops
|we will set the Y position of the "Slope Detector" to 1 pixel below wherever the "On Floor Detector is" like this:
|
| - set Y position("Slope") to Y position("Player Body") + "Player Body" height + 2
|
|Ok so use that as a refference if you ever need it.
|___________________________________________________________________________________________________________________________
--------------------
- X L O O P S -
--------------------
Go into the group "X loops"
First set an event that starts the loop, this loop starts only when it needs to, like this:
+ horizontal("Player Body") <> 0
- start fastloop("Xmove") Abs(horizontal("Player Body")) times
Basicaly whenever we need to push the player right or left, we start a fast loop called "Xmove", We make it loop the
absolute value of the amount we are moveing at the time. This is because if we are moveing at 3 pixels per frame, when
we overlap a backdrop, we could be overlapping it by them 3 pixels. Therefore if we have a loop going the same amount
that we are pushing it will push back the correct amount so you are perfectly colliding with that wall.
Now we are going to concentrait on actualy moveing the player with thease loops we have just started.
Going right:
+ on loop "Xmove"
+ NEGATE: "Right Detector" overlaping a backdrop
+ horizontal("Player Body") > 0
- set X position("Player Body") to X position("Player Body") +1
- *set all detectors positions* (explained in section "detector positions")
Going left:
+ on loop "Xmove"
+ NEGATE: "Left Detector" overlaping a backdrop
+ horizontal("Player Body") < 0
- set X position("Player Body") to X position("Player Body") -1
- *set all detectors positions* (explained in section "detector positions")
Now we are going to deal with the collisions on the "Xmove" loop.
Collide wall right:
+ on loop "Xmove"
+ "Right Detector" overlaping backdrop
- set X position("Player Body") to X position("Player Body") -1
- set horizontal("Player Body") to 0
Collide wall left:
+ on loop "Xmove"
+ "Left Detector" overlaping backdrop
- set X position("Player Body") to X position("Player Body") +1
= set horizontal("Player Body") to 0
The next thing is the "On ground bool" value we gave to "Player Body", this mainly helps with slopes, but will be used
again, so its best to do now.
On ground?:
+ "On Floor Detector" overlaping backdrop
- set On ground bool("Player Body") to 1
- set Cur Jump("Player Body") to 0
Not on ground?:
+ NEGATE: "On Floor Detector" overlaping backdrop
+ NEGATE: "Slope Detector" overlaping backdrop
- set On ground bool("Player Body") to 0
Ok now just to more conditions with events then we will have finished our X movement, all we have to do now is slopes!
Basicaly all we are saying if your on the ground and your left or right collision detectors arent touching the background
we push tot eh top of the ground (a slope), so! if you wanted to be able to travel up higher than 1 pixel slopes (wich
is 45 degrees) then all you have to do is shorten you left and right collision detectors.
Lets code that,
Going up a slope:
+ on loop "Xmove"
+ "Floor Detector" overlapping backdrop
- set Y position("Player Body") to Y position("Player Body") -1
- *set all detectors positions* (explained in section "detector positions")
Going down a slope:
+ on loop "Xmove"
+ On ground bool("Player Body") == 1
+ NEGATE: "On Ground Detector" overlaping backdrop
- set Y position("Player Body") to Y position("Player Body") -1
- *set all detectors positions* (explained in section "detector positions")
Ok so that is our X section finished. Lets move on to the Y section.
--------------------
- Y C O N T R O L -
--------------------
Go into group "Y ctrl"
First we will set the constants:
+ Run this event once
- set extra jumps("Player Body") to *However many extra jumps you want your player to have, i choose 0*
- set gravity("Player Body") to *how fast to fall, i choose 4*
- set jump str("Player Body") to *how high to jump, i choose 10*
Now we deal with what happens when the player presses the "jump" button:
+ Player presses Fire 1
+ "On Floor Detector" overlaping backdrop
- set cur jump("Player Body") to cur jump("Player Body") +1
- set vertical("Player Body") to jump str("Player Body")
Now the jump str is the absolute maximum the player can jump, and we can acheive that by holding shift (the next code),
so we want it that if the player isnt holding shift, to bring him down early.
Player limits the jump height:
+ NEGATE: Repeat while Fire 1 pressed
+ vertical("Player body") > 0-gravity("Player Body")
- set vertical("Player Body") to vertical(Player Body) -1
If you decided to put in a double jump this is the code for it:
+ Player presses Fire 1
+ vertical("Player Body") <> 0
+ cur jumps("Player Body") < extra jumps("Player Body")
Now we need a natural gravity that plays a part aswell. otherwise when you hold shift you would keep going up til you let go.
Natural gravity:
+ vertical("Player body") > 0-gravity("Player Body")
+ NEGATE: "On Ground Detector" overlaping backdrop
- set vertical("Player Body") to vertical(Player Body) -1
Now we want to stop us falling through the ground, make sure that your backdrops are obsticals.
Collide with floor:
+ "Floor Detector" is overlaping backdrop
- set vertical("Player Body") to 0
Same with head detector:
+ "Head Detector" is overlaping backdrop
- set vertical("Player Body") to 0
YAY thats it for the Y control, now lets look at the last section, Y loops.
--------------------
- Y L O O P S -
--------------------
Go into the group "Y loops"
First set an event that starts the loop, this loop starts only when it needs to, like this:
+ vertical("Player Body") <> 0
- start fastloop("Ymove") Abs(Vertical("Player Body")) times
You know how all this works now, lets just show the code.
Going up:
+ on loop "Ymove"
+ vertical("Player Body") > 0
- set Y position("Player Body") to Y position("Player Body") -1
- *set all detectors positions* (explained in section "detector positions")
Going down:
+ on loop "Ymove"
+ vertical("Player Body") < 0
- set Y position("Player Body") to Y position("Player Body") +1
- *set all detectors positions* (explained in section "detector positions")
Floor Collision:
+ on loop "Ymove"
+ "Floor Detector" overlaping backdrop
- set Y position("Player Body") to Y position("Player Body") -1
- *set all detectors positions* (explained in section "detector positions")
Head Collision:
+ on loop "Ymove"
+ "Head Detector" overlaping backdrop
- set Y position("Player Body") to Y position("Player Body") +1
- *set all detectors positions* (explained in section "detector positions")
So thats how to acheive custom platform movement! This tutorial included:
Left and Right movement with collisions
Up and Down movement with Collisions
Multible jumping
Slopes
Compleatly controled by varables so you can mod the movement.
These are: speed, jump hight, amount of extra jumps, gravity.
|