-
Gravity for enemies
Is there a easy way to make enemies with gravity? I`m making a platform game, I made a lot of enemies some of them have gravity that I programed using colision box. The problem is. I f I have 2 of them coliding each other and I kill one of them the one who has been killed "steal" the colision box from the other.
Is there a easy way to make an enemy with gravity without using colision box? I ve tried to use fastloop however it appears that don`t work with more tham one instance of the same object. =(
-
Yes, if you have behaviors for an object and multiple instances of that object, movement can get wonky because mmf doesn't know which instance it's supposed to apply behaviors to, so it usually goes for the most recently created one (or something like that). You need the ForEach object extension:
ForEachSetup2.exe
Run your loops through this and everything should work.
Put an instance of the ForEach anywhere in the field and use something like the following code:
Always:
-->ForEach Instance... Start ForEach Loop for Object... "Enemy Movement"... Select Object... Enemy
ForEach Instance... On ForEach Loop for Object... "Enemy Movement"... Select Object... Enemy
-->Enemy... Set Flag 1 on
-->Fast Loops... Start Loop... "Enemy Gravity"... Gravity Times
-->Enemy... Set Flag 1 off
On Loop... "Enemy Gravity"
+Enemy... Flag 1 is on
-->Gravity Movement
I know this code is incomplete, but I don't know exactly how you want your gravity to work, so... just play around?
Good luck.
-
Hey, thanks man! =D
Do you know if this have a big performance impact?
-
Well like always when optimizing, try to make sure to stop your loops when you don't need them. The "Always" condition should be changed to something a little more specific to your project. Also, like anything else, limit your transparencies and total number of objects, optimize your sounds, organize your code, and track your frame rate in standard display to make sure. But I've gone all over, including this board, many times to try to fix optimization problems (that's actually when happygreenfrog gave me this extension). Don't plan for performance lag, just do the best you can to prevent it and deal with it when it comes.
But that small little code snippet shouldn't cause problems, rather it should fix them because you don't need to create individual, identical objects with lines and lines of code for each.
-
Thanks man! Unfortunatly It is still having problems with the instance.
I made a small test with no gravity however with terrain correction for irregular terrain
Is in play area = > start for each loops for enemy 1
ok
them
ON LOOP (ENEMY1UP) -> set enemy 1 y-1
ON LOOP (ENEMY1DOWN) -> set enemy 1 y+1
FOR EACH OBJECT ENEMY1
COLISION OVERLAPING BACKGROUND -----> START LOOP ENEMY1UP 10TIMES
FOR EACH OBJECT ENEMY1
(NEGATE) COLISION OVERLAPING BACKGROUNS) --------> START LOOP ENEMY1DOWN 10 TIMES
It worked with 1 enemy, when I put 2 in the screen if one of them start to go up the other one go up too. So the fastloop act with the 2 stances. =(
Sorry for my bad english
-
Don't have to waste time with apologies for bad english. I think it's fine.
You're forgetting the flags during your foreach loop. This will make each of them run independently.
It should be something like this:
Is in play area:
-->Start ForEach loop "Enemy Move" for Enemy
On ForEach loop "Enemy Move" for Enemy
+Enemy is overlapping a backdrop:
-->Set Enemy Flag 1 On
-->Start Loop "EnemyUp" 10 Times
-->Set Enemy Flag 1 Off
On Loop "EnemyUp"
+Enemy Flag 1 is on:
-->Set Enemy y to Enemy y-1
-
Woah, it is working now! =D
Hey, thanks man I didn`t knew that I had to use flags
Thanks again! =)