angle() function question

Discussion and feedback on Construct 2

Post » Tue Nov 11, 2014 11:41 pm

Just do a "is in touch"
sprite set angle to angle(self.x,self.y,touch.x,touch.y)
With the hotspot set to the 0 x.
Image ImageImage
B
169
S
50
G
174
Posts: 8,330
Reputation: 110,804

Post » Tue Nov 11, 2014 11:45 pm

newt wrote:Just do a "is in touch"
sprite set angle to angle(self.x,self.y,touch.x,touch.y)
With the hotspot set to the 0 x.


Yeah well in this case the angle of the sprite will go in all 360°, i needed only 90° based directions.
See

http:(erase this space)//bricklayer-milks-47242.bitballoon.com/
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

Post » Wed Nov 12, 2014 12:09 am

I think, for this instance, you would be better off determining if the "snapped" touch xy is greater than, less than etc of the initial touch position.
The angle serves no purpose.
Image ImageImage
B
169
S
50
G
174
Posts: 8,330
Reputation: 110,804

Post » Wed Nov 12, 2014 12:18 am

newt wrote:I think, for this instance, you would be better off determining if the "snapped" touch xy is greater than, less than etc of the initial touch position.
The angle serves no purpose.


Yep should work.
But again my angle logic should have worked with brute js code :p
It's okay I'm learning the limitations of some event stuff in c2
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

Post » Wed Nov 12, 2014 1:41 pm

Construct 2 is working correctly, the problem is your own comparisons. -135 degrees is mathematically identical to +225 degrees, so both answers are equally correct. The problem is you are making linear comparisons that are not aware of the cyclical property of angles. You are expecting only one of the possible set of correct answers.

Use the Sprite object's angle conditions instead, which are cycle-aware - for example "is within 90 degrees of 0 degrees" will match anything in the -90 to +90 degree range, or +270 to +90, or +270 to +450, etc. since they are all mathematically identical ranges and the math used in the condition is cycle-aware. Funnily enough this exact issue came up on the forums recently and I realise not everyone uses the Sprite object for this type of thing so the next beta should have those features as system conditions as well.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Thu Nov 13, 2014 1:07 am

Ashley wrote:Construct 2 is working correctly, the problem is your own comparisons. -135 degrees is mathematically identical to +225 degrees, so both answers are equally correct. The problem is you are making linear comparisons that are not aware of the cyclical property of angles. You are expecting only one of the possible set of correct answers.

Use the Sprite object's angle conditions instead, which are cycle-aware - for example "is within 90 degrees of 0 degrees" will match anything in the -90 to +90 degree range, or +270 to +90, or +270 to +450, etc. since they are all mathematically identical ranges and the math used in the condition is cycle-aware. Funnily enough this exact issue came up on the forums recently and I realise not everyone uses the Sprite object for this type of thing so the next beta should have those features as system conditions as well.


Thanks Ashley :)
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: Baidu [Spider] and 20 guests