Platform Movement Object How-to + Fancy Stuff
Author: | Assault Andy
|
Submitted: | 5th September, 2003
|
Views: | 23357
| Rated: |
|
|
Hey everyone, i just can't get enough of this object. I discovered some more things to do with this object such as powerful AI which i will include at the end of this article.
Before we begin you may want to grab my example to help you along this article.
http://www.create-games.com/downout.asp?id=3445
Or the new one with AI can be found at:
http://www.angelfire.lycos.com/jazz/ajvitalize/PME_Tut.zip
Now let's begin
Firstly the Platform movement object (PMO) is almost as simple as the built in platform movement that comes with mmf, and it is certainly more powerful. Some people have told me that they have become confused with this object, so i'm going to go through the code after to tell you what it all means. You'll need to put on your screen an active object, a background (obstacle) and the PMO. Here's the code:
Start of frame - (PMO) set object to Active
PMO}Test for obstacle overlap
+ active is overlapping a background - PMO} Selected object overlapps a background.
Repeat while player moved right - User is holding right input key.
Repeat while player moved left - User is holding left input key.
Now the code starts off telling the PMO that we want to control the active object, it then next uses some code to detect collisions between the active and the background. Now since this is an extension and not built in it cannot detect what a bacground object is, therfore we must tell it. By stating if the active object overlapps a background. The next two commands are pretty straight forward, move left and right. These actions are useful if you wanted to invert the movement so right is left and left is right. All you would have to do is swap them around. If you run the game now, you should be able to move: left and right without falling through the floor.
Extra
If you want to be able to jump through platforms from underneath, tick the jump through platform collisions box in the actual PMO object. Then change this line:
PMO}Test for obstacle overlap
to
PMO}Test for jump through platform overlap.
Now this makes every background object that is an obstacle jump throughable from the bottom, if you only want some to be able to be jumped throughed from the bottom; use active objects for those few platforms instead.
Next
You're sure to want to be able to jump, so you have two ways of doing this:
1. PMO} Object is standing on ground
+ Upon pressing fire 1 - PMO} Jump
2. Active is overlapping a background
+ Upon pressing fire 1 - PMO} Jump
Depends what type of game you are planning but both work well.
Fodo(Maker of PMO) has included a nice feature to the extension, the Jump Hold. Which means the longer you hold down jump in the air, you can jump higher. The minimum jump is under jump strength and the extra jump is under Jump hold strength. To enable it you need to add some more code:
Object is not standing on ground / overlapping a background
+ Repeat while fire 1 is pressed - PMO} user is holding jump in the air.
Run the game again and your active should be fully moving, this is the basic engine and all that needs doing is adding some special effects. (And Animation)
Animation
This is a very simple concept seeing as though Fodo has included conditions that make it easy, here is an example of how to make someone walk:
PMO} Object is moving - active.animation = walking
PMO} Object is not moving - active.animation = stopped
If you had more movements such as jumping and others you would need to include them to:
PMO} Object is moving
+ Object is not jumping
+ Object is not Falling - active.animation = walking
Fancy Stuff
This section is for people who think they have mastered the basics of movement.
Springs
The jump action doesn't have to be just used when the player jumps, you can use it to simulate a spring.
PMO} Object is falling
+ Active is overlapping spring - PMO} Jump
That simple line of code allows you to put a spring anywhere in your game and let the player bounce when he lands on it.
Water
The water is just as simple as the spring, All you need to do is when the player is overlapping a water active object, set the gravity lower than it already is. Then when you're not overlapping it, set it back to normal. You also need to set the maximum y velocity lower. And lastly when the player is overlapping the water and he presses jump then jump.
Active is overlapping Water - PMO}Gravity = 7, MaxYVel = 200
Active is not overlapping Water PMO}Gravity = 30, MaxYVel = 2000.
Active is overlapping Water
+ Fire 1 was pressed - PMO} Jump
Artificial Intelligence
I came across this while staring blankly at the Player input actions. I then realised that they could be used for other things such as AI and they dont have to be used when the player inputs. Here is some code I created (It is also in the example). For this section you will need to add another PMO to your game, we can call this PMO2:
Start of frame - PMO2} Set object to AI
Active.X < AI.X - PMO2} User is holding left input key
Active.X > AI.X - PMO2} User is holding right input key
PMO2} Object is standing on ground
+ Active.Y < AI.Y - PMO2} Jump
PMO2} Test for object overlap
+ AI is overlapping a backdrop - PMO2} Selected object overlaps a backdrop.
The first two lines of this code tell the AI to move left or right, the third line tells the AI to Jump after the player if the player is higher than the AI, we don't need to tell it to fall because it does that automatically. And the last line just checks for collisions.
That's it, although this doesn't include the water like the example does, it's pretty self explanitory once you get the idea. This AI is also not very complex, it is a chasing AI.
That's all folks. That concludes this article, i hope you learnt something and remember when trying out new things with the PMO 'Think outside the square you live in
-Andy
|
|
|