0 Favourites

Pac man ghost ai

This forum is currently in read-only mode.
  • Hi i m tryng to make a basic ghost movement for a Pac man style game.i know i m doing wrong with my logic, coould anyone have a look ?

    EXCUSE MY ENGLISH

    tHX

    http://files.filefront.com/Pac+mancap/;13035504;/f

  • It does what you want except for two problems:

    1) Sometimes it continues in the same direction.

    2) Sometimes it chooses to turn into a block.

    To fix the first problem I suggest that you give the ghost a private variable old_angle.

    Then:

    + On Collision between Ghost and Block

    + while Ghost.old_angle = Ghost.GetAngle()

    - Set Ghost.old_angle to floor(random(4))*90

    I hope you can read my pseudo-code. Please let me know if you can't.

    To fix the second problem I suggest you try something like David showed in this example:

    viewtopic.php?f=16&t=2397

  • Thank you stainsor, could you show me a cap example because i still don t understand the logic in this system , in fact i dont know where to put these information, is it sub event of collision ? how can i compare a private variable and a global ?

    thank you sir

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • here what i did from your help . i really don t understand how construct works.

    http://files.filefront.com/Pac+man+2cap/;13036336;

  • i really don t understand how construct works.

    Have you tried a tutorial?

  • Sure i did but i don t understand how the while function works.For me you can pseudo code somethong like this :

    while Sprite.x<640 then add 1 to Sprite.X

    I hope we will get some easy tutorials like pac man or space invaders to understand the logic.

    I will work harder on this Beauty Soft until i understand it .

    Thank Ashley and please keep on the good work !!

  • while Sprite.x<640 then add 1 to Sprite.X

    That's pretty much what it looks like in event form too:

    + While

    + Sprite.X < 640

    -> Set Sprite X to .X + 1

  • Okay, I posted a cap of what I meant here. There are some comments in the cap that explain the details.

  • thank you Stantor , but your example doesn t work , the Ghost still pass trought the blocks !!

    .In fact i understand the idea to test the condition :

    While the new randomized Angle equal the one before collision continue to shuffle angle !

    In fact : pick any angle but the last one before collision.

    Simple !

    but still doesn t work !! does it work for you ?

    THX

  • You're correct. This fixes the first problem: Your character will no longer continue in the same direction. But the second problem still remains. Try doing something like David did in the cap posted on this thread.

    Now that I think about it if you can fix the second problem you'll probably fix the first problem anyway. So you may not need the code I gave you anyway.

    I'm actually having basically the same problem with a Pacman style game right now. But I'm planning to use either Ball movement or grid movement. I suppose I should post about it in a new thread though.

    edit: Here is the new thread.

  • Hi Stantor , i think the problem is that when ghost collide the old value is erased.What we need is to store the old value somewhere before contact and then compare it within the random expression.But i ve no idea how to do that.In python you can store and keep a value as a list ,a tuple or dictionnary.

    Could be nice if Ashley can give us a hand.

    Regards

    I ve seen you Pac man Wip and yes you need grid control.I ll have a look .

  • I have cooked up a quick example of basic ghost movement. May be not the most clever way to do it, but it works.

    I didn't really care to comment it, after all it's just 28 events. But if you need further explainations don't hestitate to ask.

  • Hi think it s genious !! but yes ! please explain it !! could be so cool for the community !!

    thanks a lot

    ps: do you have any idea how to fix the floor(random(4))*90 expression ?

    THX

  • There's nothing wrong with that expression. It will just give you one of four different directions.

    But the way you're using it won't work for what you intend to do. Since the direction you get can very well be the very same direction you just had and therefore the ghost will move into the walls. (I don't think you need the "floor" in there btw)

    I'm basically using a loop in my example that checks all four sides of the ghost and will only allow directions which aren't blocked by any walls.

    Okay I will comment my cap. Just give me a little time.

  • Okay I put some comments in there and I was able to optimize it a little at least. Uses 4 events less now. Here it is.

    If you're fairly new to Construct you still may have problems to immediately understand what's going on in there. Just give it a little time, toy around with it maybe...

    Any more questions feel free to ask.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)