Custom Movement for Dummies
Author: | Silveraura
|
Submitted: | 13th November, 2004
|
Views: | 7325
| Rated: |
|
|
First we'll start out with a little introduction to custom movement.
What the Hello is Custom?
Custom movement, for those who don’t know, is when you litterly make the engine for your game rather then using the premade, & rather buggy built in movement. Now you are most likely wondering to yourself, why the heck should I learn something complex, when I can just make 3 clicks to get the same thing? Well first things first, those 3 lazy clicks you just made, will NOT get you the same thing, infact, it will get you something that is buggy, & buggy in a way you cannot fix at runtime, or in the events, without messing something else up. Also, why learn custom? Here is a little list of just a few reasons.
Custom is extremely flexible
Custom is easier to debug when it comes to simple things like falling through platforms.
You can create allot more things, easier using custom, including an entire Sonic The Hedgehog engine featuring spin dash, springs, loops & all!
Custom is all around smoother then the prebuilt movement, if it’s done right.
So now you know just a few reasons why custom is worth learning, but don’t let me stop you just at the player engine, custom is also extremely useful with things like AI, & special FX!
So now that you are, or should be talked into why custom is worth learning, let’s get started!!
For this little example, I'm gonna tell you how you can make an extremely simple 8 directional movement in custom, that is not only more flexible then the prebuilt, but is also, ALOT smoother!
First things first, when you create a new application, place a simple object like the default MMF diamond inside the frame, but do NOT give it any of the prebuilt engines, as soon as you place the object into the frame, right click on it & go to properties, & click on Alterable Values. Now name the first 2 Alterable Values there, XPosition & YPosition, now incase your wondering, this has nothing to do with the actual engine itself, this is just a nice way to keep track of the values, so you know exactly what you’re working with when we make the actual engine.
Now that we have that done, jump over to the event editor.
First, we want to make it so that when the player presses either right or left, the Alterable Value XPosition is added or subtracted to. So what we want to do first is make it so that when the player presses RIGHT, add, let’s say 2, to XPosition, & when the player presses LEFT, subtract 2 from XPosition.
Now let’s repeat this for Up & Down. Only this time, we are going to use the Alterable Value, YPosition. That way, when we press down, it adds to YPosition & when we press up, it subtracts from YPosition!
What the!?
Now if you where to go & test this right now, you wouldn’t notice a thing! That is because right now, all we are doing is adding & subtracting from these values! Right now, we gotta make it all work.
So enter the event editor, & create the Always event. Then create the condition, Set X Position of object to the X Position of that object, + the Alterable value, XPosition. This is how it would look.
X( Active )+XPosition( Active )
Now we need to do the same thing for the Y Position, so repeat the sets, only do it for the Y position, & add in the condition
Y( Active )+YPosition( Active )
After those are added in, test it out, you will notice when you press the keys, the object will start to move around.
UH OH!!
Ah ha! Now once you started to test it, you will notice that once you old in the button a little longer then oh say 1 second, the object will blast out of the screen like a jack rabbit with its butt on fire! This will be your first experience at DEBUGGING!
First you need to find out why the problem exists. The problem here is because, when you hold the button in, it keeps adding & adding & adding to the number, making the object increase in the number of pixels it jumps. This is easily fixed. All you need to do is set a max & min value to the object. Let’s make the Max, maybe 6, & the Min. -6. This way, the object has enough le way to move around, but it won’t jump any where over 6 pixels at a time. Now say you want to make the object slow down when the person isn’t holding a key. This again, is easily fixed. Just make the event, when player is NOT holding Right or Left, & the XPosition is greater then 0, subtract 1, & then, when player is NOT holding Right or Left, & the XPosition is lower then 0, add 1. Now do the same thing, only for the YPosition value & the Up & Down keys.
Now what this is doing here, is when the player is not holding the keys, it will detect weither it is over or under 0, so it knows weither to add or subtract, & when it does add or subtract, it takes the value down or up to 0, thus, taking away the number of pixels the object will move at a time, making the object slow down! Then, when the object is 0, it won’t be greater or lower then 0, & the game will leave it alone!
Now go ahead & test her!
You'll notice now that the object is moving ALOT smoother. Also, you will notice that when you move from say right to left instantly, the object slows down before it turns in the other direction. Not to mention it moves around smoother, & doesn’t seem to jerk around!
What you just now did, was custom!
HOW DOES IT WORK!?!?
Basically, you made the engine, but how does it work?
Basically what the game is doing is, when you add numbers to say the XPosition, the game is detecting them, & moving the player to the right, because it is taking the original of the object, & moving it over number of pixels you are telling it too. Now how does work with negatives. Well it’s as simple as the math problem. 5 + (-10) = -5 The game is taking the position of the object, adding the negative number, but intern, is actually subtracting the number. This also makes moving from 1 direction, instantly to another direction, allot smoother, because say you are currently moving 5 pixels at a time, to the right because the XPosition is set to 5, when you press left, the number starts to subtract from 5, making the number of pixels the object is moving at a time, slowly start to move down, until it reaches 0, goes into the negatives, & starts to speed up again in the other direction!
Also, because you are using 2 values, XPosition & YPosition at the same time, they are working together with each other, making turning allot smoother, because they are both fighting for the position of the object, but 1 is fighting for the X position, & 1 is fighting for the Y position. So when 1 places the object a number of pixels X, the other places it a number of pixels Y, & they push the object around the arena. The same goes with the computer mouse & the ball mice. There are only 2 bars inside the mouse, 1 moves the mouse up & down, 1 moves the mouse left & right. The combination of the 2 bars, makes it possible for the mouse to get anywhere around the screen.
So now that you know how to make a simple 8 directional custom engine, you can explore the great abilities of it on your own! I will say though, that where I don’t use it often, the Fast Loop extension is found to be very useful in custom movement!
Well, that’s all for this article. Good luck! Hopefully this will make the use of custom in click games, even higher!
Brandon Cassata
www.CassataGames.tk
|
|
|