I can knock out AI with no problem, but when it comes to enemies and gravity, I can't figure out how to do it in mass.
Any help would be appreciated to point me in the general right direction.
Thanks!
-Nick



I can knock out AI with no problem, but when it comes to enemies and gravity, I can't figure out how to do it in mass.
Any help would be appreciated to point me in the general right direction.
Thanks!
-Nick
you might want to look into the Move Safely 2 object; it won't do gravity (which is relatively easy for multiple objects), but it'll handle the collision/pushout routines for those objects (which is somewhat complex)




Have one detector for all of the objects. (A floor detector, eg a 32x2 pixel rectangle placed just below the object's feet.)
At the start of the frame, and when the number of enemies changes, spread a value through all of the enemies.
Always run a loop.
On loop (you can possibly use an always for this)
+ Alt Val A of enemy is equal to loop index.
Then
Enemy y = Enemy y + 1
On loop
+ Alt Val A of enemy is equal to loop index.
Then:
Set detector x/y to object's feet.
On loop
+ Alt Val A of enemy is equal to loop index.
+ Detector is overlapping the backdrop/ground
Then:
Set Alt Value B (or a flag) of enemy to 1.
On loop
+ Alt Val A of enemy is equal to loop index.
+ Alt Val B of enemy is equal to 1
Then:
Enemy y = Enemy y - 1
Basically what is happening is, you have one detector that fits on all your enemies. Then on each loop it sets its position to the current enemy, whos ID/alt value matches the loop index. If it is overlapping a background while it is in this position then we flick a flag for that active, and on the next event it moves that object back up 1 pixel.
I have used this many times in many engines without problems. You can expand on it and make it really complex with edge detection amongst other things, all while using just one detector object. It has never caused slow down either.
It doesn't even need to be that complicated unless you plan to have a high terminal velocity coupled with thin platforms and short enemies. All you really need to do is store two values in each object: one for how fast it's falling and one for it's y position. Each frame, you increase the falling speed by a certain amount (according to how strong you want gravity to be, and only so long as it's below your desired terminal velocity), add the current falling speed to the Y position variable, then set the object's Y position to the Y position variable. (You add because MMF is Y-down, not Y-up, and the reason you use a separate Y variable instead of changing the object's Y directly is because it makes the movement work a lot better because it can store decimals.) Then, if the object is colliding with the background, reset the falling speed to 0. MMF will automatically bounce the object back up to the top of the surface. Add a collision mask test using the object's bottom edge and you're even set for odd things like flying sideways into obstacles, all without using any sub-objects.
If you reserve the same two alterable values in each object, you can apply gravity to any object you want simply by assigning these events to a qualifier rather than a particular object.