Gradually move to specific location

For questions about using Classic.

Post » Thu Jun 02, 2011 4:11 am

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:

[code:261noit0]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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Jun 02, 2011 5:32 am

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.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Thu Jun 02, 2011 5:40 am

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Jun 02, 2011 6:12 am

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
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Thu Jun 02, 2011 2:56 pm

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Jun 02, 2011 6:41 pm

[quote="Juryiel":13crlf3w]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.[/quote:13crlf3w]

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
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Thu Jun 02, 2011 10:56 pm

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu Jun 02, 2011 11:44 pm

[quote="Juryiel":17bv6r2f]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.[/quote:17bv6r2f]

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.[/quote:17bv6r2f]

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.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Fri Jun 03, 2011 6:04 am

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





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 :)
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri Jun 03, 2011 7:09 am

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.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests