How do I - Randomize Object Movement

0 favourites
  • 9 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hello all.

    I am currently working on a game prototype that is akin to Shark Evolution or Chicken Evolution. In those games, the objects have random idle movements that they do at occasional intervals independent of all other objects on the layout.

    I have managed to emulate to a certain degree the random movements with the below event chain:

    However, while the objects do move in random directions at random speeds, they move together. When the fifteen second mark hits they both will shoot off in a random direction, instead of doing so separately. Any ideas on how to make it so that the object chosen to move is random out of those that are available on the layout?

    Thanks in advance.

    Edit: I've come to discover that the mobs only shoot off in a random direction when they hit/land in certain invisible barriers. Basically what I'm now needing to know is how to make it so that when the objects enter a specific invisible area they are repelled back toward the main area. I have collisions set to off due to the fact that the objects need to be able to wander around and travel on top one another, otherwise they fuse automatically by themselves and I'm trying to avoid that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For your first Problem a possible solution:

    • Give the stg1lv1 object a variable called timer
    • Set the timer to a random value at creation
    • Each Second Subtract 1 from this timer
    • Make a condition if instance variable timer is <= 0 -> Change direction, speed -> set timer to random (value1,value2)

    For the second question

    i am not sure if you have disabled the collision detection or the physical bullet collision.

    if collision detection is on you could make an on collision with another object event, then calculate the angle based on your objects position relative to the barriers position and then reverse it and set it as the new angle of movement.

    Hope that helps

  • I have turned collisions back on and successfully managed to make it so that when the objects touch the border, they bounce back off of it. Your suggestion for individual movements is interesting, and I will take a crack at it.

    I'm still having the problem of being able to drag the mob inside of the invisible area. They freeze and are unable to move, instead of being repelled back toward the center of the layout. I'm unsure how to go about fixing that.

  • ...they both will shoot off in a random direction, instead of doing so separately.

    Try adding a "For each" condition.

  • The problem of independent movement has been solved, though I'm still having issues with being able to put objects in an area they shouldn't be and being unable to make them move out of that area on their own.

    Having said that I hit the event limit of the free edition last night, so I'm screwed until I can get the personal license.

  • By what manner are you putting objects in areas they shouldn't be? Are they supposed to wander out gradually or teleport out instantly?

    You might be able to simplify/refactor your project, 100 events can go a long way. Otherwise, you can also try working on different parts of your game or mechanics in separate projects.

    If you post a capx, that would make it a lot easier to help with your problem, and also maybe compact your event sheet too.

  • I did intend to do that, but I'm fairly certain that I'm going to be able to acquire a license on Friday.

    As for your question, the objects are being dragged into the area. They are indeed meant to wander out on their own.

    I will post a capx soon, any and all comments (constructive) are welcomed and appreciated.

  • That would work perfectly. It will take me a bit of time to reverse-engineer it and understand exactly what you did and where best to apply it (I'm thinking OnFunction will be necessary), but it's a perfect example of what I needed.

    The capx for my prototype can be downloaded here:

    w w (remove the spaces in the www). Any helpful tips are appreciated.

    Edit: I updated the file a couple minutes ago, managed to free up about 27 event slots. Having issues implementing the suggestion in a working manner. The corners are extremely screwy...

    Edit 2: Managed to get the movement working properly. I had to add an invisible, uninteractable object in the center of the layout and set the object angle to its position.

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