How to make random movements for an Idle Villager-ish type of game?

0 favourites
  • 9 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hello!

    Newbie user here~ just want to ask what will be the logic/event processing if i want to make a certain sprite do a random movement.

    The Idea is for a idle village type of game, so the villagers will be moving randomly around the village without fixed direction (well maybe it will have a fixed movement once a parameter is met like if its hungry it will go to a food source).

    I was thinking it'll be like:

    for X: floor(random(8))*choose(1,-1)

    for Y: floor(random(8))*choose(1,-1)

    then increasing the numbers for bigger movements.

    I just can't fully wrap around my head on the events and processing script (im not good at programming as well). T_T

    Hope to have some helping hands and some theory so i can reverse-engineer it.

    Thanks for reading this post!

  • I'd use the pathfinding behaviour for this. This is how it would look like:

    - Every X seconds > Find path (in a radius if you want)

    - On path found > Follow path

    This is the most simple implementation, you can then add obstacles like houses where they can't go, or use this same behaviour to make them go to a food source as you said.

    Here's a minimal implementation so you can run it and modify it: filebin.net/esgn6z1z99bbnzor

  • Hello!

    Newbie user here~ just want to ask what will be the logic/event processing if i want to make a certain sprite do a random movement.

    The Idea is for a idle village type of game, so the villagers will be moving randomly around the village without fixed direction (well maybe it will have a fixed movement once a parameter is met like if its hungry it will go to a food source).

    I was thinking it'll be like:

    for X: floor(random(8))*choose(1,-1)

    for Y: floor(random(8))*choose(1,-1)

    then increasing the numbers for bigger movements.

    I just can't fully wrap around my head on the events and processing script (im not good at programming as well). T_T

    Hope to have some helping hands and some theory so i can reverse-engineer it.

    Thanks for reading this post!

    This is a simple example of a random move that requires a minimum of resors. but this is not suitable for intelligent units, only zombies or other stupid enemies can move like this.

    File *.c3p

    If you need a really smart unit, you'll have to build a smart script that will control it and drive it along routes depending on the time of day, for example, and its other needs. It is more difficult to create a competent AI than a protagonist.

  • I'd use the pathfinding behaviour for this. This is how it would look like:

    - Every X seconds > Find path (in a radius if you want)

    - On path found > Follow path

    This is the most simple implementation, you can then add obstacles like houses where they can't go, or use this same behaviour to make them go to a food source as you said.

    Here's a minimal implementation so you can run it and modify it: filebin.net/esgn6z1z99bbnzor

    Hi molter!

    Thanks for the help and for the script! Really helped me understand the theory and logic!

    Did some random numbers so the movement stops can be random as well.

    Again, thank you!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • random() can't be use like that.

    If you want the event to be triggered every 2-5 seconds, use random(2,5)

    Or, if you want it to be in 0.5s intervals, use choose(2,2.5,3,3.5,4,4.5,5)

  • random() can't be use like that.

    If you want the event to be triggered every 2-5 seconds, use random(2,5)

    Or, if you want it to be in 0.5s intervals, use choose(2,2.5,3,3.5,4,4.5,5)

    I see, TIL!

    Additional question! If i make a copy of the sprite with those random movements, they will all have synchronized movement right? (tried it)

    So to prevent that from happening, do i need to make a at least 5 different sprites with different random movements or is there a way to make it efficient? Like i dont want them to do synchronized movement in case the village reach 10 population (it doesn't look natural if they all move the same every random intervals).

  • In this case you should use random(2,5) time.

    do i need to make a at least 5 different sprites with different random movements

    No, it's a bad idea. You can randomize movement properties like speed for every instance of the sprite. For example:

    Sprite on created -> Sprite set maximum speed to random(80,100)

    Making diffe

  • > random() can't be use like that.

    > If you want the event to be triggered every 2-5 seconds, use random(2,5)

    > Or, if you want it to be in 0.5s intervals, use choose(2,2.5,3,3.5,4,4.5,5)

    I see, TIL!

    Additional question! If i make a copy of the sprite with those random movements, they will all have synchronized movement right? (tried it)

    So to prevent that from happening, do i need to make a at least 5 different sprites with different random movements or is there a way to make it efficient? Like i dont want them to do synchronized movement in case the village reach 10 population (it doesn't look natural if they all move the same every random intervals).

    To build on what dop2000 said: If you want each instance to do something different every time you should use "For Each". (https://www.construct.net/en/make-games/manuals/construct-3/system-reference/system-conditions#internalH1Link5)

    It will loop the actions once for every instance of your sprites/villagers. You could then randomly decide (inside that loop) if that villager will move or not, and how much.

  • Hi guys, thanks for the help!

    I resorted on using random movement events for each villagers (since they'll be limited, at least 20 max). I'm still figuring out on doing 1 event for all of them but i just can't get it to work, haha

    At least i have some villagers randomly walking across the map and its a good start.

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