Sunday, January 18, 2015

How to make the AI walk around seemingly random but with nice constraints.

The monsters in our server are kinda stupid.
(Yeah we had an AI in the past but not a lot of thought was put into it, it turned out buggy/laggy and had weird problems).
Most notable all monsters walking towards a point on the map that is way off in the distance.

I aim to fix that sort of problem.

Needed a way to get random numbers within a range but preferring certain ranges over others
Such as walk a distance of between 70 and 120 preferable to a distance of 30-50.
(But still allowing to walk a short distance randomly.)

If anyone is coder/math person what are your thoughts on this, ignoring how bad Math.random is,
( It does not go all the way to 1 so you could never get 100 by doing Math.random() * 100 )

I have not tested if this is correct yet just written it up might do some charts/graphs later to verify.

http://codepen.io/LiamKarlMitchell/pen/QwvyJy


The idea for using this is that monsters that roam around will prefer to wander in the existing direction or turn slightly.

That they will prefer to walk medium to short distances over long.

And then a constraint later to keep them walking around the center of their spawn area/roaming within bounds.


We could configure this to be closer towards where they exited the region, tweaking will be needed.


Areas we spawn monsters in can be considered either points or rectangles.
They are spawned at a point we define (things like guardian stones some boss etc) or within a rectangular region.

If spawned at a defined point we would expect the monster to not roam.

If spawned within a rectangle we would expect the monster to roam within that rectangle, possibly allowed to go slightly outside up to 50 units (could be configurable in config).


The idea is that this kind of movement would let monsters roam around close to their spawned area (you will notice this in real server as a grouped area they spawn in I think this is most noticeable in underground/caves where spawn count is high and re spawn time is low)



When a monster is attacking a target or chasing it will be allowed to roam outside of its area.
If it looses sight of target for more than 10 seconds (should be configurable) it should de spawn and re spawn within its area or chosen point.


You can see example of the monsters moving like this here: http://codepen.io/LiamKarlMitchell/pen/raxRKq

Try adding a small or ranged using the drop down and button.
Middle mouse button down changes the query and spawn circle to the mouse position.
Try different combinations, to see the results of combat press F12 and look  in the console.


16 comments:

  1. I found these sites, I am sure they will help.

    http://natureofcode.com/book/chapter-1-vectors/

    https://www.khanacademy.org/science/physics/two-dimensional-motion/two-dimensional-projectile-mot/v/visualizing-vectors-in-2-dimensions

    ReplyDelete
  2. Actually quickest reference for moving the way i wanted was the first slide of this.
    http://www.rodedev.com/tutorials/gamephysics/

    ReplyDelete
  3. when it will be over :) i cant wait

    ReplyDelete
  4. Pls Liam give us an update every month , sometime u afk like 6 month in a row its insane lol

    ReplyDelete
    Replies
    1. So you would prefer blank posts with no content?

      Delete
    2. Liam I would wait even 1 more year for a good update, what I can say is that I appreciate all ur work and devotion on making TS1 what it was before, best mmo ever.

      My question to you is how u will manage to make hackers not able to create hacks that will work on TS1?

      Delete
  5. Regarding your roaming issue why not separate the monsters available movement options into 3 distinct sub choices ( short , medium, long) where medium = 30- 50 sq units long = 70 - 120 sq units and short = 1- 20 sq units. You can use the MATH.Random function to loosely simulate probability

    int walkOption = Math.floor(Math.Random()* 10);

    if (walkOption == 0 || walkOption == 1 || walkOption == 2)
    Monster.Movement(medium)

    an so on for the other options (you could also use a Switch statement). this would give the medium distance option a 3 out of 10 chance to be selected disregarding the probability of the random number generator

    ReplyDelete
    Replies
    1. Yeah that is pretty much what I have :).
      Some tweaking may find us nicer options.

      Thanks for the comment :)

      Delete
  6. Great Job on the progress guys!!! I literally just had a dream about TS1 last night and when I woke up I Re-Downloaded and installed all the files and tried to log in with my CB username and pass and the server was red, so I read up on the changes, and I have to say its pretty amazing progress for as small a team that is working on it and GREAT job! - HSDrac011, Fujin 4 Life!

    ReplyDelete
    Replies
    1. I have a skype, but I dont use it much, in this case even if I used it I dont know anything about code, I would only be able to tell differences between what I remember on TS1 and how its like on this server.

      Delete
    2. i need ur help if u can make the options for me for ts1 thas why i asked you for skype

      Delete
    3. First, sorry I dont visit here everyday; Second,what do you mean options?; Third, If you are talking about translations and how to get the files n stuff to work to pop the server up/game start, then go to the previous post....let me find it and ill tell you the date it was posted (basically scroll to bottom of main page and click older posts/previous posts....give me a bit to find the date)

      Delete
    4. Older Posts: TSX Oct 25th PServer CB Launch is where you will find the directions, with pictures:)

      Delete
  7. This comment has been removed by the author.

    ReplyDelete