# Problem with two object and for each.

0 favourites
• 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
• Hi, can anyone explain?

This formula works with an object, but if you have two objects then the second object escapes, why ?.

https://www.dropbox.com/sh/ehrch6zye1tuq33/AACqlv_6UnWbOaJSLhy8n3Era?dl=0

• ## Try Construct 3

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

Construct 3 users don't see these ads
• If the condition in event 2 is true for the first sprite, then it has to be untrue before it can run again due the 'trigger once while true'. As a consequence, when the condition is true for the second sprite(after it was true for the first one) it will not run.

Why is the 'trigger once while true' needed ?

• If the condition in event 2 is true for the first sprite, then it has to be untrue before it can run again due the 'trigger once while true'. As a consequence, when the condition is true for the second sprite(after it was true for the first one) it will not run.

Why is the 'trigger once while true' needed ?

Okay, now I understand what you say.

If you remove the trigger the sprites are trapped in the tile, the trigger changes them once only until they re-enter the other tile and change direction again.

Thanks, I'll have to find a solution.

• Dont understand situation.

I suppose 'velocity' is the amount pixels/tick that you move the sprite.

'velocity' can be positive or negative (event 3 & 4).

There is no Y position changed, so i suppose the sprite move only horizontal.

The sprite can approach the tile from the left and from the right. (neg and pos velocity)

We look in the future (x+velocity) and when sprite overlaps a tile, it gets positioned just outside the tile.

Then its velocity is mirrored. So far the basics. As far as i understand them.

When the sprite is approaching from the right (negative velocity) it gets positioned outside the tile on the right side of the tile.

But. When the sprite is approaching from the left, it gets ALSO positioned outside the tile on the right side of the tile (tile index * 32 PLUS 16). Now it is flying trough the tile. The positive velocity is set to negative, as a result it returns (starts moving to the left) inside the tile (AGAIN) the next tick. And is indeed locked up.

I think it should be (again if i understand it right, i dont see the layout, so sorry if i am again wrong)

For each Sprite

______________ Set sprite to the future

___ Sub event :The tile check condition

____________Sub event : velocity > 0 <--- means it is approaching coming from the left.

___________________action: set outside tile .. = (tile index * 32) - 16 <------ on the left side

___________________action: make velocity positive

____________Sub: Else <--- means it is approaching coming from the right.

___________________action: set outside tile .. = (tile index * 32) + 16 <------ on the right side

___________________action: make velocity negative

• I guess that's another way to do it.

I just removed the trigger and added a bool variable in the object and now it works.

https://www.dropbox.com/sh/ehrch6zye1tu ... n3Era?dl=0

• 5 posts