How do I Set Up Proper Artificial Intelligence?

0 favourites
  • 4 posts
From the Asset Store
10 Beautiful Pokemon-like Building Pixel Art Sprite Sets
  • What I want to happen is for the enemy to chase the player.

    I also need him to randomly set an attack. Which I planned on doing by set wep to random(1,3) Then if wep = blah blah use attack.

    I was hopping for some help on how to do this because my distance formula doesn't seem to work as he will either infinity use his weapon (if set to greater than) or never use it at all (if set to less than).

    I also need him to do things on the Y-axis by jumping and such but I figured I could figure that out later.

    If I am going about this in all the wrong ways please tell me

    Any and all help is appreciated,

    thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The problem is that random(1,3) is almost always greater than 1 and never smaller than 1.

    Random returns a float between either 0 and a-1, if you use

    random(a)[/code:3dxdpj8i] or a and b if [code:3dxdpj8i]random(a,b)[/code:3dxdpj8i] This means that it can return 1.024566 or 2.478962. You could set wep to [code:3dxdpj8i]floor(random(3)+1)[/code:3dxdpj8i] and comparing if it is 1. That way it has an equal chance to return 1.564585, 2.024566 or 3.478962, which will round down to the nearest integer (1, 2 and 3, respectively). I recommend [code:3dxdpj8i]choose(1,0,0)[/code:3dxdpj8i] which will randomly choose between those three, so 1 has a 1/3 chance, and the two 0's have a total chance of 2/3.
    
    Distance can be replaced by [code:3dxdpj8i]abs(player.x-testenemy.x)[/code:3dxdpj8i]
  • Thank you very much on both aspects. I knew there was something I had to add to the random part and I just couldn't remember.

  • Thank you very much on both aspects. I knew there was something I had to add to the random part and I just couldn't remember.

    It is very important to remember what kind of output you get and convert appropriately. I hope you know what int(), string() and float() do and how to use them. I've failed many times because I didn't know random returns a float. Good luck in your project!

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