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

Get help using Construct 2

Post » Fri Nov 20, 2015 9:44 am

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! :D
B
8
S
2
G
3
Posts: 14
Reputation: 2,187

Post » Sat Nov 21, 2015 2:47 am

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[/u][/b]: ... = 10
a = 355, b = 5: ... ( ( ( 355 - 5 ) + 180 ) - floor( ( ( 355 - 5 ) + 180 ) / 360 ) * 360 ) - 180 355[/u][/b]: ... = -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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
B
26
S
17
G
8
Posts: 322
Reputation: 6,017

Post » Mon Nov 23, 2015 10:59 am

Thanks a lot for you're thorough answer, fisholith! :) I'll have a shot at this!
B
8
S
2
G
3
Posts: 14
Reputation: 2,187

Post » Mon Nov 23, 2015 4:09 pm

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))
B
85
S
27
G
85
Posts: 5,073
Reputation: 57,880


Return to How do I....?

Who is online

Users browsing this forum: menos30, Moordhuis, RetroSpock, TRMG and 7 guests