Why doesn't this event work?

0 favourites
  • 3 posts
  • Hey guys, I'm trying to set an instance variable called "FallSeconds" on each instance of an object based on it's velocity at it's angle.

    Img:

    I am using this formula to calculate the velocity at an angle: cos(ANGLE)*OBJECT.physics.velocityX + sin(ANGLE)*OBJECT.physics.velocityY (Thanks to R0J0hound for the formula)

    Then if it's >50, every 0.1 sec I add 0.1 to the "FallSeconds" var of that specific object

    If it's <50 I set it once to 0.

    (I need the FallSeconds var to check if the object fell too much and destroy it)

    My problem is that instead of checking for each object's velocity and adding only to that object's variable, it picks only one object to check the velocity and sets all other object's variable according to that velocity. (i checked this with the "cursor is over object" event)

    I have tried adding a "Pick all OBJECT" event, as well as leaving it empty, but it had no effect, and when I added a "For Each OBJECT" event, it would only work on 1 object and the others would not change...

    So, do you guys know what I'm doing wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are you saying that all blue boxes have the same FallSeconds value?

    I really don't like using events like "Every x seconds" and "Trigger once" inside of the loops.

    Try removing "trigger once" and move "Every 0.1 seconds" above the "For each" loop. See if it fixes the problem.

    If not, I suggest you enlarge your text field and add some debug output to the loop (because "Cursor is over sprite" is not a reliable method).

    So you can do something like this:

    Every 0.1 second
    For each Egg_collisionCheck    Text append newline
       cos(....)>50  Add 0.1 to FallSeconds
                     Text append "ID:" & Egg_collisionCheck.IID & "+0.1=" & Egg_collisionCheck.FallSeconds &"  "
       Else          Set FallSeconds to 0
                     Text append "ID:" & Egg_collisionCheck.IID & "reset  "
        
    [/code:2qembwov]
    
    This will help you to understand what exactly is going on.
  • dop2000 Thank you very much! Looks like the "Every X seconds" event was the problem.

    I guess the events in the loop would terminate when it would move on to the next index, thus not triggering anymore the "every x seconds" event.

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