Custom Platform Movements , Easily Done
|
NOTE: An engine has been released after updating the techniques given in the following article , it is recommended you use that for custom platform movements , to check it out go to http://www2.create-games.com/download.asp?id=6113
--------------------------------------------------
Ok, i've seen many klikers here using Platform engines in their good games , turning them into bad ones. TGF built-in platform engine is one of the most idiotic thing one can do for his game. And most of the players know that you are using the built-in engine when they jump and get stuck to a ceiling upside. Stop using it then , custom movement is better , give it a try
Tutorial:
Basis:
We'll simply set 2 objects according to the position of the player so that they are set at its two edges , i.e. Up and Bottom, and we'll use them to detect collisions as doing it with the player object will be impossible.
Setting up the objects:
1)First draw 2 small objects , of about size 8x8
2)Give each of them a name , according to the edges they'll be used to detect.
3)Open up the Events Editor and set an event Always:
A)Set Position Of 'Bottom Edge' to 0,20 from Position of the Player ( You may need to change the X,Y value , according to the size of your player )
B)Set Positions of the Upper Edge similarly , and continue
Moving your player horizontally:
1)Set a condition that when the Player Object is not colliding against an obstacle ( you can use any object as an obstacle ) and the player is pressing the Forward Key:
A)Set direction of Player Object to Right
B)Set X Position of Player Object to X Position of Player Object + 4 ( + 4 will determine the speed of your object , you can change it as you like )
2)For moving left , just check for a left arrow key press and the player is not colliding against an obstacle:
A)Set direction of Player Object to Left
B)Set X Position of Player Object to X Position of Player Object - 4 ( -4 here , as above will determine t he speed of your object while moving in left direction )
Acceleration/Deceleration:
If the player object is something like Sonic , you may need to add acceleration/deceleration to its simple horizontal movements , doing that is simple , in the events editor add the following:
1)When right arrow key is pressed + Value of B of Player Object is < 10 ( where 10 is the maximum acceleration ) and player is not colliding against an obstacle and every 0.20 seconds:
A)Add 1 to value of B of Player Object
2)If you are using acceleration/decleration with the normal horizontal movement of your object then you need to edit the normal horizontal movement lines to work with the values of acceleration or decleration just replace the normal 'Set X Position of Player Object to X Position of Player Object + 4' with 'Set X Position of Player Object to X Position of Player Object + Value B(player object)' and offcourse edit the + or - signs according to forward or reverse horizontal movements.
To decelerate your object , just add few more lines in the events editor:
1)When right/left arrow keys are not pressed and value of B is greater than 0 and every 0.20 seconds ( adjust it as you want to ):
A)Substract 1 ( adjust this value as you like )from value of B of player object
2)When right/left arrow keys are not pressed and the player is looking in the right direction:
A)Set X Position of the Player Object to X Position of Player Object + Value B(Player Object)
2)When right/left arrow keys are not pressed and the player is looking in the left direction:
A)Set X Position of the Player Object to X Position of Player Object - Value B(Player Object)
And now your object have Acceleration / Deceleration as well. If you want to keep only one of them for your player then just don't add the events for the other one.
Moving it vertically:
Gravity:
First of all, we'll work with the Gravity. We'll use the variable A for recording all the gravity values. Right now we'll take 10 as the maximum gravity value , this determines how high your player can go.
1)Set a condition in the events editor that when the Bottom Edge is not over a background obstacle and the value of A is less than 10:
A)Add 1 to value of A
This will keep bringing your player object down if its not over a background obstacle.
2)If the Bottom Edge collides against a background obstacle ( this means it has landed somewhere ):
A)Set 0 as the value for A
This will stop the player object from going any further
3)The above events will simply setup the correct position of the player as the value of A. To bring the actual player object at the correct position in the playfield simply set an event that when the value of A is greater than 0:
A)Set Y Position of the Player Object to Y Position of Player Object + Value A of Player Object
And , now your Player will follow all the rules of Gravity
Jumping:
Once you are done with gravity , making your player jump is a lot easier.
1)In the events editor we'll just check if the Bottom Edge object for the player is over an obstacle and the player has pressed the Jump key ( you can use any Key as the Jump Key ):
A)Substract 12 from the value of A. You can increase the number if you want your player to jump higher.
2)Alternate value of A is less than 0 ( if its above the ground level ) and its Upper Edge is not colliding against an obstacle:
A)Set Y Position of the Player Object to Y Position of the Player Object + Value of A of Player Object
3)If the upper edge of the player is over an obstacle background then:
A)Add 2 to value of A
This will stop the player from keep going up , if it collides against a ceiling object/obstacle.
And now Stop , using the built-in platform engine.
Additional Stuff:
If you are making a platform game where there are slopes , then the horizontal/vertical movements used above won't make them move according to or on those slopes. For that you just need to add few more lines in the events editor:
1)If player object is over an obstacle background:
A)Set Y Position of player object to Y position of player object -1
2)If player object is not over an obstacle but the bottom edge is:
A)Set Y Position player object to Y Position of player object +1
And Thats it!
|
|
|