Problem with Random Tile Movement

0 favourites
  • 5 posts
From the Asset Store
Grid Movement 1 Engine
$7.50 USD
50% off
A template for a grid movement , grid tactics type game like Dofus , click on the grid you want to move to and the
  • I've created an abbreviated project to demonstrate a problem I'm having with random movement.

    This project is called Random-Movement.c3p.

    There's one PLAYER object that moves right or left across the top row of a grid.

    There are 4 Killer objects placed in the lower right area of the grid.

    Every time the PLAYER moves, I want the 4 KILLER objects to move either UP or LEFT, depending on the result of a "random(2)" outcome.

    The problem I'm having is that the KILLER objects ARE randomly moving UP or LEFT, but ALL 4 KILLER objects are moving in unison, rather than independently. I would like them to move independently (some of them UP and some of them LEFT).

    I can't figure out how to attach my whole project here. For now I just copy/pasted an image of the Event Sheet:

    I think I found how to share the project. Here's the shareable link:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • aryd

    under event 3, add a subevent that says: For Each Killer

    then put the random, and else lines as subevents under that.

  • Thank you so much. your solution worked. I've been dealing with this problem for weeks, developing other parts of my game, but realizing that it will never work right if I can't fix the random movement problem.

    I still wonder why I had to use the "for each" condition. Since all 4 KILLER's were moving randomly, but in unison, it appeared to me that Construct 3 had a bug. But I see now that after reading and re-reading the chapter on "How Events Work," I still don't fully understand the logic flow of events.

  • aryd

    in general, if you don't specify "For Each" C3 will treat objects as a group (so, in your case they all get the same random number because the actions are only executed once). With the For Each, the actions are run individually for each object and they all get a different random number.

    so, performance is better without the for each, but if your game logic requires individual control then for each is the way to go.

    it gets even more confusing when you add "self" to the mix. You can have something like:

    every tick, Killer.X = self.X + 5

    That doesn't require "for each", but each one will have 5 added to their individual X coordinate.

    However, Killer.X = self.X + Random(5) would require "for each" if you wanted them to each get a different random number.

    But once you understand how events work and how picking applies actions to objects you can do amazing things!

  • I assumed that my Event 3 line, "KILLER | Is Move_Killer_Instance" would PICK all KILLER's individually, since it explicitly refers to the KILLER object. That was my understanding from reading "How Events Work." I'll have to go back to read "How Events Work" yet another time to get a better understanding.

    Personally, I think Construct 3's manual should have more examples to go along with the technical material.

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