How do I add points when a full rotation has been done.

0 favourites
  • 4 posts
From the Asset Store
ADD ME ALL
$29 USD
A super duper mental math activity to practice addition with unlimited combinations.
  • Hello fellow game dev lovers,

    Almost finished with my game just have a issue with my point system, and hope someone would be so kind helping me out with this!

    The game is about the player bouncing all the time. You can press left and right to let it rotate around it's own axis. You get points if you have rotated a full round and landed between an angle of 180 and 0, which gives you the least amount of points. If you land between the angle of 80 and 100 you'll get maximum points.

    Since there isn't a "check if full rotation" on the Rotate behaviour I'm not sure how I can achieve this.

    Thanks in advance people!

  • Hey brandesign

    By chance, I happened to write a post on detecting full rotations a while back.

    Below is a link, and a copy of my first post in that thread.

    If you get a chance to visit the link, my second post (not included below, because it's long) goes into more detail,

    My second post also has a demo capx I made showing the tracking method in action.

    Here is my demo capx for angle tracking.

    Here is a link to my post on tracking angle changes.

    • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Text of my first post:

    (Edit) I just checked the System >> "angleDiff" expression, and it always gives a zero or positive answer, meaning it doesn't give you the direction of the change in the angle, so it won't work here.

    One possible approach is to calculate the change in angle between ticks,

    store that change in a running total,

    and track that running total instead of tracking the objects rotation property directly.

    Here is a formula that will give you the change in angle as the shortest CW or CCW rotation, and it works seamlessly across the 360-to-0 transition.

    angle_delta = ( ( ( a - b ) + 180 ) - floor( ( ( a - b ) + 180 ) / 360 ) * 360 ) - 180

    Where a and b are your two angles.

    e.g.

    a = 5, b = 355: ... ( ( ( 5 - 355 ) + 180 ) - floor( ( ( 5 - 355 ) + 180 ) / 360 ) * 360 ) - 180 355: ... = 10

    a = 355, b = 5: ... ( ( ( 355 - 5 ) + 180 ) - floor( ( ( 355 - 5 ) + 180 ) / 360 ) * 360 ) - 180 355: ... = -10

    Remember, if you compare two angles with a difference greater than 180 degrees, the angles will be treated as a shorter rotation in the opposite direction.

    e.g. A raw difference of +270 is treated as -90.

    As long as the total distance rotated per tick is less than 180 degrees that shouldn't be a problem though.

    So, to use this in place of directly tracking the object's angle property, you can do the following:

    Create a custom variable "unwrapped_angle".

    Every tick, get the change in angle between ticks, angle_delta( currentAngle , angleRecordedLastTick ), and add it to "unwrapped_angle".

    Then you should be able to use the unwrapped_angle in place of the objects built-in angle property.

    • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • Thanks a lot for you're thorough answer, fisholith! I'll have a shot at this!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just to add onto fisholith's excellent post, here is an alternate equation that also gives a signed angle difference.

    angle_delta = angle(0,0,cos(b-a),sin(b-a))

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