How do I - Set Clock Arm to point towards Mouse

Get help using Construct 2

Post » Sun Apr 23, 2017 8:31 pm

Hi,
I just want to Set Clock Arm to point towards Mouse.

Please see the capx at below link, I have tried all the methods mentioned in various forum posts :(

https://www.dropbox.com/s/qq2f4kanf7tprnf/forum.capx?dl=0

-Thanks
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Sun Apr 23, 2017 10:48 pm

@mchulet

you were very close - and had the right idea. The main trick is to get the image points and initial angle correct.

In C2, Zero degrees points to the right, so it is a good idea to have images facing that way and then set the origin on the left edge. That way, when you set the angle to point to the mouse it will work the way you expect. The only other thing to remember is that a clock assumes that Zero degrees is pointing straight up - so you have to add 270 degrees to an object to get them to the correct place as far as the clock is concerned. Since there are 60 seconds per minute, the second hand moves 360/60 or 6 degrees every second (and so does the minute hand because there are 60 minutes per hour). The hour hand moves 360/12 or 30 degrees every hour.

you can download my version of your capx here: http://www.rieperts.com/games/forum/clock.capx
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Mon Apr 24, 2017 5:21 am

@AllanR amazing work, you also improved the graphics :)

really appreciate your help
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Mon Apr 24, 2017 10:23 am

@AllanR another question, for an arm to be pointing to specific time ex: Hour Arm pointing to 8PM or Minutes arm pointing to 50Mins, is it possible to find the angle it should be at ? like validation to check if its 8PM then the arm should have been rotated to 170degrees otherwise the rotation done by student is wrong...
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Mon Apr 24, 2017 1:35 pm

@mchulet

I just grabbed a random clock face from a google search :) and then made the hands smaller so they fit on it.

Yes, you can calculate any angle you need from a given time, or check the time from an angle. So, if the time is 8:50, then the angle for the hour hand will be 8 x 30 + 270, and the angle for the minute hand will be 50 x 6 + 270.

the general formula from a given time is:

number of minutes x (360 / 60) + 270

number of hours x (360 / 12) + 270


or if the hands have been set, and you want to know what time they were set to:

hour: round(((clockarmhour.Angle+90) / 30)%12)

minute: round(((clockarmminute.Angle+90) / 6)%60)

seconds: round(((Sprite.Angle+90) / 6)%60)


(We have to add 90 degrees to get the angle back to what C2 understands - since we added 270 earlier. If we subtract the 270 out, then we get negative numbers that are slightly harder to deal with. At the end we have %12 or MODULO 12 to keep the hours between 0 and 12. The minutes and seconds have %60 to keep those numbers between 0 and 60)
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Tue Apr 25, 2017 7:07 am

@AllanR Thank you, detailed explanation was very helpful.
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Thu May 11, 2017 4:03 am

@AllanR can you please guide on the subdivision of Hours angle while the Mins hand moves from 0 to 60 ...
B
13
S
3
Posts: 76
Reputation: 1,679

Post » Thu May 11, 2017 4:48 am

mchulet wrote:@AllanR can you please guide on the subdivision of Hours angle while the Mins hand moves from 0 to 60 ...

The hour hand moves around the clock every 12 hours, that is 360 degrees in 12 hours or 30 degrees per hour.
B
12
S
1
Posts: 24
Reputation: 611

Post » Fri May 12, 2017 1:54 am

@mchulet

like @NoSoul8 said, the hour hand moves 30 degrees per hour (360/12). The minute hand moves 6 degrees per minute (360/60).

Since there are 60 minutes in an hour, that means that the hour hand moves 30/60 or 0.5 degrees every minute. So, you take the number of minutes and multiply it by how much the hour hand moves per minute:

if the minute hand at the 6 on the clock face (30 minutes after hour), the hour hand should be half way between two hours (30 minutes x 0.5 = 15 degrees).
if the minute hand is at the 9, then the hour hand should be at 45 minutes x 0.5 or 22.5 degrees past the hour it started at.
if the minute hand is at the 2, then the hour hand should be at 10 minutes x 0.5 or 5 degrees past the hour it started at...

so, if the time is 4:15 then the hour hand will be at 4 x 30 + 15 x 0.5 = 127.5 degrees, which will place it a quarter of the way past the 4.

(obviously, you still have to add in the 270 degrees to get the hands positioned relative to 12 o'clock, because C2 thinks zero degrees is at 3 o'clock)
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Wed May 17, 2017 2:18 pm

@AllanR I need an inverted clock i.e. Clock that has 12 below and 6 above for two players to play against each other. For the inverted clock I set the initial angle to 90 instead of 270. This places the hour arm to proper 12 Clock position but all the other calculations go for a toss.

@NoSoul8 Thanks
B
13
S
3
Posts: 76
Reputation: 1,679

Next

Return to How do I....?

Who is online

Users browsing this forum: plinkie, zenox98 and 15 guests