for example, i have redbox, bluebox, and yellow box. redbox and bluebox is added directly to stage, but the yellow box is added to the bluebox. the yellow box will try to align itself between the redbox and bluebox.
but then when i moved the red box to be close enough to the blue box, the angle starts shaking. i found out that the angle calculation becomes weird because the global coordinate from bluebox:localtoglobal returned different results each enterframe (value a then value b then value a again, then value b and so on)
here is the project . you can move the redbox using joystick with click and drag on the screen
thanks
edit :
wrong attached files, here is the correct one
zip
zip
Comments
oops sorry about that, i've corrected my post
So what you're doing in the onEnterFrame event is basically altering the rotation, which is having the effect of altering the local -> global mapping each time, so the results are likely to be different on each call to onEnterFrame, hence the "wobbling" you're seeing.
That's my best guess on a quick look.
hmm, you're right. localToGlobal should return the global coordinate shouldnt it? then maybe this is a bug?
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Because the yellow is a fixed distance away from the blue and the red is closer to blue than yellow then the math falls over. It may be that you have to separate yellow from blue and calculate the new position of the yellow yourself using the angle calculated from red & blue.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
i've revised the project to better illustrate what i want to achieve. So, the reason that i use localToGlobal with the local coordinate of the yellow box(now 45 deg yellow box image) is that i want to make the yellow box to point the red box.
The idea is that i have certain gun attached to some character shoulder. the gun will be slightly rotated (yellow box represents the gun and the blue box represents the character's shoulder while the redbox is the target). the gun local coordinate and degree is exactly the same as in this project
However, if I change the localToGlobal to 0,0 and then change GUN_ELBOW_ANGLE = 25 it pretty much works as I think you intend it to. Obviously once it gets too close to the yellow box, that can no longer point to the red box but then, if you think about it, if it's a gun, you'd have to start twisting your wrist anyway to point to something that close.
Does that help at all?
well , i tried enlarging the blue box, but it's still get different results each enter frame.
and yes, that'll solve the problem for now. but it still count as bug right? as it differ with what the documentation state
but thanks!