Posted By
|
Message
|
superpower
Registered 07/06/2010
Points 27
|
11th June, 2010 at 09:30:49 -
Yesterday I came up with a nice way to do enemy player detection for my platformer and I thought I'd share it with you.
If you are used to doing this with the calculator you might want to skip this.
If your like me though, and like to use hitboxes (detectors), you might find this helpful.
Usually what people do, is make the enemy shoot out hitboxes, but this can create quite alot of them if you have multiple instances of enemies in the frame. Sure you can limit the event so that it only occurs when the enemy is near the player, but still, I find this way "cleaner".
What I did is REVERSE the concept like this:
• Every 0,05 seconds
• If "Enemy"(X-position) >= "Player"(X-position) - desired number of pixels
• If "Enemy"(X-position) >= "Player"(X-position) plus (I can't post the plus symbol for some reason, sorry ) desired number of pixels
• (do the same for the Y-position, if you want/need to)
• Pick one of "Enemy" at random
--- Make "Player" Shoot "Enemy LoS Hitbox" at 0,0 from "Enemy"
• "Enemy LoS Hitbox" is overlapping obstacle
--- destroy
• "Enemy LoS Hitbox" is overlapping "Enemy"
--- Set "Enemy alterable value "Chasing" = 1
For this game I will make the hitbox destroy itself upon leaving the window but alternatively I have been using something that also might come in handy to some of you (It's basic, veterans can probably skip it).
• Every 0,03 seconds
--- add 1 to Alterable Value "Death row" of "Enemy LoS Hitbox"
• When Alterable Value "Death row" of "Enemy LoS Hitbox" >= *(desired value)
--- Destroy
Because Alterable values are individual this creates a "life span" for your hitboxes and makes them destroy themselves at a fixed distance from you. This creates a really handy "Line of Sight"-type effect.
For example in stealth games make the "*(desired value)" lower in the dark to simulate, well... darkness.
Also what I like about this is that you can adjust the speed of the shooting and life span of the hitbox to get the desired reaction time for the enemy.
PS.
Qualifiers are GOD!
- Superpower out...
Edited by superpower
n/a
|
GamesterXIII
Registered 04/12/2008
Points 1110
|
12th June, 2010 at 14:52:55 -
Checking to see if the player is close to the enemy is pretty basic. I'm a bit of a perfectionist and using "shoot object at player" seems like it would work a bit differently every time.
For example if you were 50 pixels away from an enemy, it would take slightly longer for the enemy to react than if you were 20 pixels away due to the object having to travel. Thats like saying it takes you longer to spot someone at 50 feet away rather than 20.
You should replace the shooting event with a fastloop (or incorporate the loop into it) that pushes the detector 1 pixel over per loop. That way the reaction speed is exactly the same every single time.
n/a
|
superpower
Registered 07/06/2010
Points 27
|
14th June, 2010 at 07:18:03 -
Originally Posted by GamesterXIII Checking to see if the player is close to the enemy is pretty basic. I'm a bit of a perfectionist and using "shoot object at player" seems like it would work a bit differently every time.
For example if you were 50 pixels away from an enemy, it would take slightly longer for the enemy to react than if you were 20 pixels away due to the object having to travel. Thats like saying it takes you longer to spot someone at 50 feet away rather than 20.
You should replace the shooting event with a fastloop (or incorporate the loop into it) that pushes the detector 1 pixel over per loop. That way the reaction speed is exactly the same every single time.
I myself use a completely different system. I only do platformers and have always used a huge hitbox that follows the player and covers the entire area where I wan't the enemy to follow the player, because I can easily make them stop following when they're not overlapping it...
Anyway, you can make the shooting speed over 100 in MMF2 so that's enough for me. Why I liked this system is that the hitbox would fly at the enemy no matter in which direction of the player he was. But I suppose you're right about using in-built functions like shooting. How do I do the same with a fastloop that pushes the detector 1 pixel per loop!?
Edited by superpower
n/a
|
UrbanMonk BRING BACK MITCH
Registered 07/07/2008
Points 49667
|
14th June, 2010 at 15:15:25 -
No!
Keep doing what you are doing.
Fastloops in mmf are ineffecient. If you can get away without using them do it. You'll be glad you did later if you want to export to something like flash which is even worse with fastloops, or java that crashes with nested loops.
And not only that but in this case it would be better to measure the distance using the distance formula then strech an active to check for collisions. It's faster, I tried it.
Edited by UrbanMonk
n/a
|
|
|