When using Orbit, best way to keep track of revolutions?

0 favourites
  • 11 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Does anyone have a suggestion for the best way to keep track of number of orbits using the orbit behavior?

    Rotation gives you the angle you are at, so conceivably you could store the starting angle, then when it hits it again you increment a counter.

    I'm trying to program 2 revolutions, then start accelerating the opposite direction, go 2 revs then repeat...

    but Orbit.Rotation wraps 0-360 back to 0 again.. so if you start at 200 going CCW it will go to 360, then back to 0 then to 200. so its hard to count.. it's not like other rotations that keep going up.

    any suggestions?

  • Out of interest what "other rotations" are you comparing it to? The rotate behaviour doesn't have a custom angle expression, and the instance angle expression is clamped the same way that the orbit behaviour is.

    If this is something people think is useful we could potentially add a "orbit count" expression and a "clear orbit count" action. Modifying the angle clamping behaviour at this point would be a breaking change, and inconsistent with other expressions.

  • Rotation expression starts at 0 even when you set offset angle to 200. So you can use it like this:

    Variable counter= -1
    
    Compare two values: Sprite.Orbit.Rotation<5
    Trigger once
    	Add 1 to counter
    

    Nepeo , An integer OrbitCount will have a limited usage. I think an expression like DistanceTravelledInDegrees will be more handy. So, for example, if you need to stop after 1.5 rotations, you can do DistanceTravelledInDegrees>=540

  • dop2000 I guess they are kinda equivalent, but by maintaining the fractional part it can be useful in more ways. If we're working in fractional values of a rotation then it makes sense to use degrees instead.

    One thing I wondered is if the value should continue to increase if the rotation is reversed, or if it should decrease. I can see both values being useful for different things, but you cannot convert between them. Reversing would be the easier to implement, as we would just need to move where we clamp the value. The absolute value would be prone to minor divergence due to cumulative floating point error in 2 separate counters.

  • Nepeo I don't know off the top of my head, but I know there are other functions or actions that "do the math" for you so you don't have to worry about going out of bounds with angles. I can set a sprites angle to 580 and it works as 220. that's all I mean. I think it would be really helpful if there was a counter of degrees traveled, similar to Bullet has distance traveled.

    dop2000

    Rotation expression starts at 0 even when you set offset angle to 200.

    Not when I test it. It definitely starts at 200 when my offset is at 200. My object approaches the orbit with custom move, once in range I enable Orbit behavior so I have to set the rotation of wherever my object is in relation to the orbitee. So once it starts its orbit in my test its at 200 degrees. In order to make it circle twice then reverse is definitely a challenge, unless I were to maybe do it with a time value.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It works for me.. See this demo:

    dropbox.com/s/x2q9shvm5wdfh5d/OrbitRotation.c3p

  • jobel in the case of passing angles in the values are immediately clamped to a valid range, which is why they behave correctly. Orbit does this as well. In this case your extracting an angle from the plugin, the internal values are already clamped so you can't get this reverse effect. As far as I'm aware this is standard across the runtime code.

  • I've made some tweaks for this in the next beta release:

    • TotalRotation expression
    • TotalAbsoluteRotation expression
    • ResetTotalRotation expression

    The difference between the absolute and non-absolute variants is that for non-absolute CCW rotation will decrease the total value, but for absolute it will always increase. Reset just clears these counters and has no effect on the behaviour otherwise.

  • Nepeo this is amazing! thanks so much! I think it's a helpful modification (not just because I need it). Are the "expressions" events or variables? i.e. IF Orbit Total Rotation or Orbit.TotalRotation? I noticed there's currently only 1 event for Orbit and that's IF ENABLED.

    dop2000 - ahh I see, I'm setting the rotation to the current angle, you are setting the offset to the current angle. the only problem with that, is you always have to adjust for your offset if you want to know where the object is in the orbit.. which sort of a pain. If I want to know when my object is at the 3 o'clock position I have to calculate it with whatever my offset is.

  • They are expressions, so you will probably want to use the system condition "Compare 2 values" then compare

    MySprite.Orbit.TotalRotation with MAX_ROTATIONS * 360.

  • Nepeo excellent thanks for this!

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