Gradually move to specific location

This forum is currently in read-only mode.
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • First sorry for asking so many questions and thanks for all the help so far

    Here's my current problem. I have a bunch of Units (family of sprites) and I want to each one individually slide over from its current location to a target object in the family of Grid.

    It seems like it should be simple but i can't get it to work. What I did was I loop through each Units and do this:

    For each Units
      +Grid: Pick by Grid.Value('ID') Equal to Units.Value('Home')
           +While
             Distance(Units.X,Units.Y,Grid.X,Grid.Y)!=0  --> Units: Move 1 pixels at angle(Units.X,Units.Y,Grid.X,Grid.Y)[/code:261noit0]
    
    I would guess that the above would loop through its unit, then move it 1 pixel in the direction of the picked Grid, until the distance between them is 0.  However, when I do this, I get a warning that the While loop is infinite.
  • why do you need a while loop???

    couldn't you just move them 1 pixel towards grid until the distance is within a few pixels?

    clarify what you're saying please.

  • The call that moves them is in a function that is not called every frame, and is only called at very specific times. When the function is called, I want each unit to move alone (e.g. first Unit 1 moves, then Unit 2 moves and so on and so on) and i want the movement of all units to resolve before continuing on with the rest of the program. I might not understand how construct works precisely, but I was under the impression that without some way to stay inside that function, it would just move the unit 1 pixel per function call.

  • You've got two issues there, not sure which one specifically is causing the infinite message.

    First off a loop will stop frame rate till its finished, that is to say it is not frame rate dependent, so the move would be pretty much instantaneous. Second the distance between all the points may never equal exactly zero.

    Possibly a little from column a, and a little from column b.

    Might try a separate variable, like if pvmove equals 1 move at angle

  • Oh I see, i used similar methods in other programs but it's true that I'd call the rendering functions each loop iteration. I guess construct doesn't let you do that. Not sure how I can use the PV to do it since I'd want to basically stay in that block of code until all units have moved. Maybe I can figure out a different method to do it, perhaps something involving enabling and disabling groups, that seems like it might work.

  • Oh I see, i used similar methods in other programs but it's true that I'd call the rendering functions each loop iteration. I guess construct doesn't let you do that. Not sure how I can use the PV to do it since I'd want to basically stay in that block of code until all units have moved. Maybe I can figure out a different method to do it, perhaps something involving enabling and disabling groups, that seems like it might work.

    groups and pv's work essentially the same way.

    An example using the Object Pairer since I don't think that picking via pv would work too well from the actions side. And another pv (length) since picking via system compare wont work with multiple instances.

    +> on your trigger Units set Units.Value("move") to 1

    ->For eachGrid

    -->For each Units Compare a private variable Units.Value('Home')= Grid.Value('ID') Object Pairer pair Grid and Units

    +> Units compare a private variable Units.Value("move") = 1

    ->For each paired Units Units: Move 1 pixels*(something*timedelta) at angle(Units.X,Units.Y,Grid.X,Grid.Y)

    -->Units set private variable Units.Value("length") to Distance(Units.X,Units.Y,Grid.X,Grid.Y)

    --->Units compare a private variable Units.Value("length") is < small value

    ---->Units set private variable Units.Value("move") to 0

  • Maybe I'm misunderstanding, but won't this allow other stuff to happen unless I put all other code that isn't in this function under a condition that checks all of the units PVs and returns 0 for each.

    Instead I could have "Main Game Events" group and an "Animate Units" group and alternate between them which seems similar but easier to the above. I would also want each unit to complete its entire movement before another unit moves but i can probably keep track of that with some global or some such.

    Anyway thanks very much for the help and explaining how this works. I think I get it enough to think about waht specific implementation I want to use and how to get it done.

  • Maybe I'm misunderstanding, but won't this allow other stuff to happen unless I put all other code that isn't in this function under a condition that checks all of the units PVs and returns 0 for each.

    Not only that, the -->, and --->, are sub events of sub events.

    [quote:17bv6r2f]Instead I could have "Main Game Events" group and an "Animate Units" group and alternate between them which seems similar but easier to the above. I would also want each unit to complete its entire movement before another unit moves but i can probably keep track of that with some global or some such.

    Yeah the problem with groups and multiple instances is that when you disable a group, you disable all movement for all instances whether they have finished moving or not, and you keep all instances moving to the target continuously, even if they are already there.

    Also there is a minor bug/"feature" that when you restart a layout, groups do not keep the preset of enabled/ disabled.

  • So I got this to work but now have another issue that probably has to do with similar misunderstandings of how construct works as previous ones I made in the thread. First, here's how I implemented it:

    I made 2 groups, "Main Game Events" and "Animate Movement"

    "Animate Movement" Group has teh following code (+> denote subevents/conditions -> denote actions)

    EDIT: Replaced code with image

    <img src="http://dl.dropbox.com/u/30864403/Untitled.png">

    That all works great. However, I want to put a Delay action before the Units: Move 3 pixels at blah blah blah. The reason is that I want to do some sort of priming effect to grab the player's attention to the unit that is about to move (so I'd put the actions for that effect right before the Units: Move action so something like, resize unit, delay, resize unit back, delay, Units: Move, etc etc).

    When I put in a delay, even if it's 1ms, it breaks everything, and causes ALL the units move not to the grids objects corresponding to them, but to grid objects in order from 1 to whatever number of units I have, and ALL units move together. To me this suggests that my picking for both Units and Grid is somehow broken by that delay, and it's just picking the first objects created by UID, etc. Why, and how can I fix it? Thanks again

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Eeek the wait object.

    Ok I see you have the system compare as a subevent, with distance... I was wondering how the heck picking wasn't broken.

    Anyway the Wait object is unfinished and is probably whats causing the issue.

    Might try the Timer behavior, its broken as well, but only for additional timers on the same behavior.

  • Got the timer to work for a single delay. I guess if I can only have one timer per object, that means I need to use variables in conjunction with the On Timer command?

    It's wierd that just getting the program to halt for a preset amount of time is nontrivial, considering all the complex things I can do by just clicking a few things.

  • Its either that or add more pv's ad do some thing like:

    +>every 1000 milliseconds

    ->compare a private variable pvtimer is >1

    -->add one to pvtimer

    +>compare a private variable pvtimer is >3

    ->do stuff

    But the nice thing about that or the timer behavior is that that can be used anytime you like outside of the group.

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