Rotation prob

Ok I’m trying to basically make an arrow in the middle rotate till it points at the button you rolled over. Each button gives a value for “rot” when you roll over it. 0 degrees is up. I dunno if that’s important or not. It’s probably always up = 0… heh. Anyway this is the a/s for the “arrow” in the middle. It’s instance is arcpoint. Here it is:\r\rif (_rotation<>rot) {\r if (((rot-_root.arcpoint._rotation)<=5) and ((rot-_root.arcpoint._rotation)>=-5)) {\r _root.arcpoint._rotation = rot;\r } else if ((Math.abs(rot-_rotation))<(Math.abs(360-(rot-_rotation)))) {\r _root.arcpoint._rotation = _rotation+10;\r } else if ((Math.abs(rot-_rotation))>=(Math.abs(360-(rot-_rotation)))) {\r _root.arcpoint._rotation = _rotation-10;\r }\r}\r\rI know some of this stuff could probably be shortened but this is how I got it working so far. :slight_smile: The problem is the second half of the a/s. The part where it picks a direction clockwise or counter. If it goes clockwise (which I had it working fine at the start) it points at the button fine. But the problem kicks in when it tries to go clounterclockwise. It will always pass the button and point down and flicker back and forth. Any help is much appreciated as always. :wink: \r\rEdit: Ok I’m surprised people are even looking at this at 1 am but thats beside the point of this edit. I think it has something to do with the else if statements conditions overlapping so that’s what makes it wiggle back and forth. Then again I could be wrong. I’m trying to analyze the conditions but my brain hurts and it’s early (or late…). :frowning:

Use different trace(whatYouNeed) inserted in there, to check the values.

Are you looking for the arrow to turn until it points in the right direction and then stop, or are you looking for more like a compass needle where it goes back and forth a few times finaly settling on the correct direction?\r\reither way, the code you have wont work quite right… I’ll think about how you can do this, though probebly POM or Supra will have a solution before me. :slight_smile: \r\rHave you read up on radians?

OK, so the buttons do something like _root.arcpoint.rot = 30 ; right ?\r\rpom 0] \r\rMan, you put 1,000 brackets in that code, it’s totally unreadable. I think that you can loose some of them (I hope !)

First of al, that code is the exact same one as yours, only it’s a little clearer :

  onClipEvent (enterFrame) {\r\rif (_rotation<>rot) {\r\r        if (Math.abs(rot-_rotation)<=5) {\r\r                _rotation = rot;\r\r        } else if (Math.abs(rot-_rotation)<Math.abs(360-rot+_rotation)) {\r\r                _rotation = _rotation+10;\r\r        } else if (Math.abs(rot-_rotation)>=Math.abs(360-rot+_rotation)) {\r\r                _rotation = _rotation-10;\r\r        }\r\r}\r\r}

pom 0]

hey, pom, love your footer, how’d you do it?

Well, it’s duplication and fading… I found the effect at ultrashock’s (under the name ‘supermouse’ I believe) to be perfectly honnest. They have some very nice stuff there. I’m glad you like it !\r\rConcerning that trouble with angles, I can’t get it to work. Flash handles angles like @#%$. I’m gona try another half an hour, and they give up or I’ll get crazy. Upu, help !!\r\rpom 0]

OK, that’s the best I could do… Still bugging, but better. The code is :

 onClipEvent (load) {\r\rflag2 = 1 ;\r\r}\r\r\r\ronClipEvent (enterFrame) {\r\r&nbsp &nbsp &nbsp &nbsp diff = rot - _rotation ;\r\r&nbsp &nbsp &nbsp &nbsp if (_rotation<>rot) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if (Math.abs(diff)<=5) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _rotation = rot;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag = 0;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag2 = 1 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp } else if (diff>0&&flag2) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp shift = + 10 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag2 = 0 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp } else if (diff<0&&flag2) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp shift = - 10 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag2 = 0 ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  if (flag) _rotation += shift ;\r\r&nbsp &nbsp &nbsp &nbsp }\r\r}

pom 0]

lol ya I have quite a few brackets in there. It was getting late and I didn’t really care. But anyway, that last one with the circles and flags looks to be working pretty good. What I’m wanting it to do is travel the least degrees possible to point at its new target. But hey at least yours doesn’t get stuck halfway around the circle. :slight_smile: Thx for all the help so far.

Yeah, I understood what you were trying to do, but Flash reads angle like that :\r0…45…90…180…-170…-135…-90…0\rVery annoying.\r\rpom 0] \r\rOther than that, it seems to work pretty well, but for some reason, sometimes it doesn’t work…??

Hmmmm ok so you stick your a/s on the arrow and the buttons stay the same right? I’m not getting any errors in that popup window but its not moving either…

 on (release) {\r\r    _root.arcpoint.rot = -135;\r\r    _root.arcpoint.flag = 1;\r\r}\r\r

pom 0] \rSorry…

Thx I thought it might have something to do with those flags.

Yeah, flags are often vital, but very easy to forget…\r\rpom 0]

ok, here you go. the arrow travels in the shortest arc between itself and the goal.\…stance.swf\r[url=“”]…stance.fla\r:) \rjeremy

Hmm… I’l have to take a look at your fla…\r\rpom 0]

I looked at that fla and I think I have an idea of how it works. I just got back from work and tested Poms script and it works perfectly but so far the buttons I’m using are only in the top half of the circle (between -90 and 90 degrees). I tried putting one on the bottom with a number near 180 and if I rolled over right I could get the arrow to spin forever unless I moved over a new button. I’m gonna have to give that other one a try.