This should be simple math here. what the heck?

Get help using Construct 2

Post » Sun Nov 09, 2014 8:41 am

codah wrote:this update illustrates the decimal issue

You misunderstood why I supplied the capx. I'm just showing the values aren't what you think. I'm not suggesting it is the answer to your mirroring issue. 'at all'.



I just noticed the second file turned on "set angle" for the bullet behavior. How many times must I say that I do not wish to rotate things? This must be OFF. And it still tells me absolutely nothing about decimal numbers, the possibility of them, or answers any of my questions. :(
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Sun Nov 09, 2014 8:42 am

C2 is not the only thing you need help with.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Nov 09, 2014 11:21 am

DialgaBrite wrote:Alright, this is just beyond rediculous. When using text to debug my own game, it was giving me negative numbers. 225 (left-up) became -135, while 315 (right-up) became -35. And checking for those numbers, and/or the ranges that included them, still didn't make the events work, either. And the bullets still moved in the correct directions despite this.

I really truly feel like this is a complete bug now.



So I don't know much about what you are doing, but this seems like you are getting wraparound on your angles.

315 = -35
225 = -135

remember angles just mean rotating around a circle and 20 degrees = 20+360=20+360*2 but it is also equal to 20+360*(-1)
you need to be very careful with angles so that you are looking at the correct quadrant. Checking for a specific angle range can be very dangerous and lead to funny situations like this

so perhaps for what you need to do, you'll need to add a check
if angle < 0, add 360
if angle >360, substract 360

that way you'll always be in the range 0-360. By the way, getting a 0-360 range for angles is not the same as using the remainder function (%).
B
7
S
3
G
1
Posts: 184
Reputation: 1,352

Post » Sun Nov 09, 2014 11:40 am

also, if you only want to see in which quadrant you are, a simple solution:

cos(angle) is positive when the angle is to the right, negative on the left, 0 when 90° or -90°
sin(angle) is positive when the angle is to the bottom, negative on the top, 0 when 180° or 0°
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Sun Nov 09, 2014 1:05 pm

Angles are cyclical so it's not reliable to use linear comparisons with them. 225 degrees = -135 degrees = -495 degrees etc. If you're making a comparison expecting 225 degrees, you will fail to match the other mathematically equivalent cases, in particular -135 degrees.

I'm aware Construct 2 in some places uses a 0 to 360 value, and in others it uses -180 to +180. But this is just a quirk of the way the equations work out and does not matter if you use angle-aware comparisons and calculations.

The Sprite object's angle conditions ("is between angles", "is clockwise from", "is within angle") are cycle-aware so you should always use them instead. For example any of these conditions would work (followed by the same condition inverted for the other case): "Is between -90 and 90 degrees", "Is within 90 degrees of 0", or "Is clockwise of -90 degrees". I note that you're using a behavior's angle of motion instead of a sprite object, so it's kind of awkward to use those conditions (you'd have to have a dummy sprite set to the bullet's angle and use the sprite's conditions...) so I've put on the todo list to port those conditions over to the System object so you can use them for anything.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,464

Post » Sun Nov 09, 2014 2:38 pm

Ashley wrote:Angles are cyclical so it's not reliable to use linear comparisons with them. 225 degrees = -135 degrees = -495 degrees etc. If you're making a comparison expecting 225 degrees, you will fail to match the other mathematically equivalent cases, in particular -135 degrees.

I'm aware Construct 2 in some places uses a 0 to 360 value, and in others it uses -180 to +180. But this is just a quirk of the way the equations work out and does not matter if you use angle-aware comparisons and calculations.

The Sprite object's angle conditions ("is between angles", "is clockwise from", "is within angle") are cycle-aware so you should always use them instead. For example any of these conditions would work (followed by the same condition inverted for the other case): "Is between -90 and 90 degrees", "Is within 90 degrees of 0", or "Is clockwise of -90 degrees". I note that you're using a behavior's angle of motion instead of a sprite object, so it's kind of awkward to use those conditions (you'd have to have a dummy sprite set to the bullet's angle and use the sprite's conditions...) so I've put on the todo list to port those conditions over to the System object so you can use them for anything.



I would really appreciate that. I was finding it pretty annoying that the "angle" had more useful conditions and actions than the bullet one, even though I couldn't use it without rotating the graphic unwantedly. Also, the bullet behavior has "compare speed" and "compare distance", but not "compare angle".

Also, thank all 3 of you for actually being helpful. I mean, I admit some of that math stuff actually did go over my head. But at least you actually told me what needs to be done.

I should also point out though, specifically in regards to the first of the three posts, that I wasn't always getting -135 for bullet behavior at 255. On another file (the one that guy uploaded), it returned -180 instead. When I tried using debug text in my own game, one time I even saw a negative sign with no number even. And then, angle for "moveto" had what I think was 255, actually return 40 point a bunch of digits, even though bullet never gave me decimals. Nothing was seeming to make sense or be consistent for me at all, even a little bit.

I wound up doing what I want using moveto, but in a different way that doesn't check for angles. I guess this is still something that will take me a while to learn. but it's not gonna stop me from doing what I want to do and spreading love. <3


Here is the final result of what I was trying to do here.
https://www.youtube.com/watch?v=SvqpX-nvUY8
I <3 cures.
B
15
S
2
Posts: 103
Reputation: 1,178

Previous

Return to How do I....?

Who is online

Users browsing this forum: plinkie and 2 guests