PDA

View Full Version : a question to "the canadian"



charmander
August 19th, 2005, 12:22 AM
Hi "the canadian",hi all

Did you remember this file….that's you give me the actions to locks the arrow direction on the moving circle…I had tried to get the value of the arrow rotation by :



arrro = arrow._rotation;

or :

arrro = getProperty("arrow",_rotation);





in the first frame in the time line,but it doesn't work correctly…and give me a negative results when the ball being left than the arrow….could you tell me what can I do to make the "text field" called arrro get it's value between 0 & 360 ((((without negative results))))

Bug.exe
August 19th, 2005, 12:24 AM
Couldn't you have just PM'd him?

charmander
August 19th, 2005, 12:27 AM
i could....but i think all fourm members can join in it....like your reply

Templarian
August 19th, 2005, 01:19 AM
doesnt flash only go from -180 to 180. or am i thinking of something else.

charmander
August 19th, 2005, 07:20 AM
i attach the file again as .fla......what you think Templarian

Lord Rahl
August 19th, 2005, 09:00 AM
Wait, so what is wrong with it? It worked fine for me. (That is if the arrow was supposed to follow the ball at all times) Btw, if you move the square under the circle, with the arrow pointing directly up through the circle, it looks like a guy in armor dancing. :P



doesnt flash only go from -180 to 180. or am i thinking of something else.

I think so.:book:

charmander
August 19th, 2005, 09:07 AM
lord rahl....

move the blue square right...and get the red ball left....the value of the arrow rotation being negative.....i want the value be bositive(bitween 0 & 360)

Lord Rahl
August 19th, 2005, 09:09 AM
lord rahl....

move the blue square right...and get the red ball left....the value of the arrow rotation being negative.....i want the value be bositive(bitween 0 & 360)
Oh, ok. I think I get it. So instead of being negative you want it to continue in the positives up to 360, right?

charmander
August 19th, 2005, 09:16 AM
yes,that what i'm looking for

ElectricGrandpa
August 19th, 2005, 09:56 AM
if(angle < 0){
angle = 360 + angle;
}



in your case, this would be:

arrro = arrow._rotation;
if(arrro < 0){
arrro = 360 + arrro;
}

charmander
August 19th, 2005, 12:11 PM
that's work ElectricGrandpa....
but the directions dosen't give the right number (it reverse the value)

i mean if the arrow pointing the red circle when it been above it ,the number being 0 not 180...

TheCanadian
August 19th, 2005, 07:43 PM
Like this? Also, why does it need to be zero degrees when it is pointing straight up?

nathan99
August 19th, 2005, 11:28 PM
yea i think that its radians that flash uses

TheCanadian
August 19th, 2005, 11:59 PM
Yep, when Flash computes angles using trigonometry, it calculates them in radians. Radians can be converted to degrees and vice-versa using the following equations:


degrees = radians*(180/pi)
radians = degrees*(pi/180)


And yes, Flash uses the -180-180 degree system. This came about because the inverses tangents used to calculate angles (Math.atan(), Math.acos(), Math.asin()) return a number between -(pi/2) and +(pi/2). So when you use the equation above to convert radians to degrees, it will return a number between
-180 and 180.

If you wanted to keep track of the rotation of a movie clip using the standard degree system (say in a dynamic text box), you could use something like:


if (angle<0) {
angle = angle+360;
}


Lastly, Flash also accepts the standard degrees system when you are setting the rotation of a movie clip. If you enter something like:


_rotation = 270;

Flash will simply convert it to match it's system during run-time. In this case, to -90.

charmander
August 20th, 2005, 12:09 AM
yes the canadian
that's looks great.....but the value of the angel big than the usual by 90......

i mean it's begin by 0 when the arrow pointing down (when the red circle under than the arrow in this case).....

i tried to increase the degrees by 90..but it's fail...because the value increased in more cases over 360

take a look in the attach file and you will understand me.......

thank you

TheCanadian
August 20th, 2005, 12:57 AM
But why do you want it to be set exactly like that. It would probally be a lot easier to change your other code than to try and manipulate the degree system.

charmander
August 20th, 2005, 06:43 AM
i will try......

charmander
August 20th, 2005, 01:28 PM
i forced to do this because i built my game over this system and i can't change it now...i tried to get the number decrease by 90 degree.....but it ravage because when the number is less than 90 the value of the arrro return negative.....

can any one give any advice......................................

Smee
August 20th, 2005, 07:58 PM
Oh boy, here we go. I don't understand why you want it like this, but alright..

You want to have the arrow point at an object, and show what the angle of the arrow is (In my examples, the object will be the mouse). You also want the angle to be shown as 0 to 360 rather than -180 to 180.

Ok, just check if the angle is below 0, and then add 360 to it if it is.


radians = -Math.atan2(Arrow._x-_xmouse, Arrow._y-_ymouse);
angle = radians*180/Math.PI;

if(angle < 0) angle += 360;

You also want the 0/360 angle to be at the bottom, so decrease (or increase, if you like) the angle found by 180 before you check if it's below 0.



radians = -Math.atan2(Arrow._x-_xmouse, Arrow._y-_ymouse);
angle = radians*180/Math.PI-180;

if(angle < 0) angle += 360;

Lastly, you want 90º to be on the right side, and 270º to be on the left, so flip the numbers.


radians = -Math.atan2(Arrow._x-_xmouse, Arrow._y-_ymouse);
angle = radians*180/Math.PI-180;

if(angle < 0) angle += 360;
angle = 360-angle;

I hope that's what you meant, it's a little hard to understand. Good luck with whatever you needed it for!

charmander
August 21st, 2005, 12:39 AM
thanks smee....

but i think there are a more deffrint between the object when it being a movie clip than when it being the mouse position........

can you explain it again (in a coincident way with the example)


thank you again........

Smee
August 21st, 2005, 02:03 AM
All you need is the x and y of the point. For the mouse, '_xmouse' and '_ymouse' are the x and y points, where as for a MovieClip they are 'MC._x' and 'MC._y'.

So it would be:


radians = -Math.atan2(Arrow._x-MC._x, Arrow._y-MC._y);
angle = radians*180/Math.PI-180;

if(angle < 0) angle += 360;
angle = 360-angle;

charmander
August 21st, 2005, 07:11 AM
i tried with your's action.....that make it change but not for the desire i look's for........

when the arrow pointing up the value been 140 and in our case it must be 180
and when the arrow pointing left the value been 107 and in our case it must be 270.......

take a look in the attached file.............

Smee
August 21st, 2005, 02:23 PM
Well, this works for me:


onClipEvent (enterFrame) {
_x = _parent.mineobject._x;
_y = _parent.mineobject._y;
}
onClipEvent (enterFrame) {

// You already know this stuff.
radians = -Math.atan2(_x-_parent.otherobject._x, _y-_parent.otherobject._y);
angle = radians*180/Math.PI;

// Show the rotation visually.
_rotation = angle;

// Flip it vertically.
angle -= 180;

// Make it 0 to 360 rather than -180 to 180.
if(angle < 0) angle += 360;

// Flip it horizontally.
angle = 360-angle;
}

charmander
August 21st, 2005, 04:09 PM
Like Every time, you solve it......thank you smee.....its looks certainly wonderful, and it work's as like as my desire....
Thank you smee, and thanks for the Canadian who help me in this file in the first time even now in this thread,and for lord rahl and Templarian and ElectricGrandpa

charmander
August 22nd, 2005, 01:11 AM
last question....

when i move the arrow with the actions in my game, i tried to bind the arrow pointing operate in a movie clip (this movie clip have a name), i tried to change the "otherobject" in your actions by this movie clip name, but it doesn't work correctly..and always pointing in first _x & _y pixel......may i forget something to add.........

Smee
August 22nd, 2005, 01:16 AM
Make sure the pathing is correct. If that doesn't work, post some code here so I can help.

charmander
August 22nd, 2005, 06:46 AM
yes smee....
i check the pathing again....and solve it......in first i had removed the :

_x-_parent.otherobject._x

and replace it by :

_root.MC

but now i change the "other object" in the action line only...and its work

thank you again...sorry for disturbing