The Daily Click ::. Forums ::. Klik Coding Help ::. Need help with Enemy AI
 

Post Reply  Post Oekaki 
 

Posted By Message

Demon Lizardman



Registered
  05/08/2008
Points
  202

VIP MemberWii OwnerI am an April Fool
6th August, 2010 at 22:56:58 -

The enemy is a casual goomba. He needs to have gravity, turns around at walls and needs to jump at an edge of a cliff. Anybody have any suggestions? I am using MMF2.

 
Lets fly off into nowhere

Jon C-B

I create vaporware

Registered
  23/04/2008
Points
  237

I'm an alien!VIP MemberWii OwnerI donated an open source project Santa Hat
6th August, 2010 at 23:09:40 -

If Goomba is overlapping background > set y position to +2
If Goomba isn't overlapping background > set y position to -2
(im not sure if the plus and minus are in the right places and for x position to)
If gooma is facing --> > set x position to +2
If gooma is facing <-- > set x position to -2
If goomba collides with object > set direction to dir("Goomba")-16

I think that should work

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
6th August, 2010 at 23:26:19 -

the platform movement object should make this pretty simple. Start by having the gooba be selected by the PMO. Then just make sure that whenever the goomba is facing left or right, then the PMO moves left/right. Set a detector at the edge, once the goomba hits the detector, then tell the PMO to jump.

That's it in the short version, now here's the long version.

You'll run into two issues using the PMO, 1 object focus, and 2 collision detection.

The collision detector can be solved by using an invisible square box, the object focus, we'll need to use some loops.

So create your goomba (call it enemySprite or something), collision detection box (just a square active, call it enemyCollision or something) and a Platform Movement Object. Make sure the sprite and the Platform Movement object do not create at start (found in the properties box). Give the collision box a few alterable values: id, pmo (set it to -1), sprite and direction.

Now, on to coding. start with an always event which starts a loop, call it "create" and set the number to the number of collision boxes (retrive data from an object, under the collsion box).

Now, the next event is just On Loop "create", spread value 0 into the collision boxes id value.

After that we do On Loop "create" and if id of box = loop index of "create" and pmo of box is = -1. Create pmo wherever and create sprite wherever. Set pmo of box to fixed number of the pmo and sprite to fixed number of the goomba sprite. Set the PMO to the collision box.

Now that we've created our objects, we'll make them move. we'll need to start another loop.

Always: start loop "move" number of collision boxes
On loop "move": spread value 0 to id of box
On loop "move", id of box = loop index, fixed of PMO = pmo of box, dir of box = -1: PMO Move left

Now, the first two is starting the loop and spreading the id value. The third does a few things, it makes sure its during the loop, it checks which box's turn it is, then it checks which PMO belongs to the box, checks the direction then moves it left. The only thing to change for moving right is the dir to 1 and the PMO to move right.

any time you want to change his direction, you simply need to say something along the lines of "box overlaps direction object: set box dir to 1 or -1(depending on the direction you want them to face)"

And to make them jump, all you need to do is the same conditions of the last loop event I mentioned, except switch dir of box condition to overlapping jump object, then replace the move to jump.

Now, if you do any events that involve the sprite (which you most likely will for animation purposes) make sure you include "fixed of sprite = sprite of box" in the conditions. likewise for anything that uses the PMO. And of course if the event only uses the box, you don't need to include the fixed number checks.

I most likely explained that like a complete idiot, so if you get lost, let me know.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Demon Lizardman



Registered
  05/08/2008
Points
  202

VIP MemberWii OwnerI am an April Fool
7th August, 2010 at 01:33:38 -

Hey Jon, do you know how the goomba's can turn around at the wall's? So far your instructions are working really well.

 
Lets fly off into nowhere

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
7th August, 2010 at 01:49:08 -

My instructions listed how to do that.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Demon Lizardman



Registered
  05/08/2008
Points
  202

VIP MemberWii OwnerI am an April Fool
7th August, 2010 at 02:22:20 -

I mean without detectors.

 
Lets fly off into nowhere

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
7th August, 2010 at 03:16:36 -

Use the collision mask. It's under the frame icon. You can set a specific coordinate and if it overlaps a backdrop or not.

FYI, using an active that doesn't move won't kill your game too much.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Demon Lizardman



Registered
  05/08/2008
Points
  202

VIP MemberWii OwnerI am an April Fool
7th August, 2010 at 03:54:45 -

I already have an enemy like that, having more than one might make the enemies more generic, than again, Goombas are generic. Also, you mean creating an active object as the collision mask, what do you mean under the frame icon?

Edited by Demon Lizardman

 
Lets fly off into nowhere

Jon C-B

I create vaporware

Registered
  23/04/2008
Points
  237

I'm an alien!VIP MemberWii OwnerI donated an open source project Santa Hat
7th August, 2010 at 04:31:38 -

Well IMO it would be alot easier to just have an object that you place to make the goomba turn around, instead of a bunch of masks or detectors

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
7th August, 2010 at 18:10:48 -

when you add your turn around event, one of the conditions should be something along the lines of Collision mask whatever coordinate is obstacle. So something like Goomba is facing right and Goomba X + 10, Goomba Y is obstacle: have goomba face left.

And Jon, what we mean by detector is simply that, an object that tells the goomba to turn around.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Demon Lizardman



Registered
  05/08/2008
Points
  202

VIP MemberWii OwnerI am an April Fool
7th August, 2010 at 19:56:55 -

Alright, I did what you told me, now how to make it jump, I used the bounce ball movement and it works really well.

 
Lets fly off into nowhere

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
9th August, 2010 at 00:11:58 -

Sorry for the late reply. Well, to jump, the simplest way to do so would be to add a counter. When you jump, it starts subtracting the Y coordinate from the jumping object. At the same time you should add to a counter. Once the counter equals a certain number, the opposite happens. Then once the object hits the ground again, then you set that counter back to 0. That will give you a very triangular jump, to make it a bit more round, do something like this:

When Counter = 0 and player jumps: Subtract JUMP VARIABLE from Enemy Y, add 1 to counter, subtract 1 from JUMP VARIABLE

When Counter = whatever and player is not touching ground: Add JUMP VARIABLE to Enemy Y, add 1 to JUMP VARIABLE

When player is touching ground: Set JUMP VARIABLE to whatever and Counter to 0.

To start the jump, you could say something like Goomba is facing the right and Collision mask Goomba X+15 Goomba Y + 10 is not an obstacle (Signifying that there is no ground there), start jump event.

Try that and see if it works.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
9th August, 2010 at 14:34:35 -

If i remember i will make you a really good example when i'm back from work using internal detectors and no PMO.

 
.

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
10th August, 2010 at 03:08:12 -

i'm working on it now btw, just really slowly because it's fairly complex for an amateur like me.

 
.
   

Post Reply



 



Advertisement

Worth A Click