0

I just wanna ask you way to do this.

How can auto rotate the house object to the line which is bottom align to the line, when the user moves the house to the line. (see example)

I know black dot and house's coordinates.

rotate example

Florent
  • 12,310
  • 10
  • 49
  • 58
Ahmet Alsan
  • 624
  • 1
  • 5
  • 10
  • There are several tasks involved here, like checking if your "sprite" (house) is close to a line segment or what the angle of this line is, etc. Where do you get stuck? – coproc Oct 15 '12 at 19:41
  • i know closest two point and sprite's center point. – Ahmet Alsan Oct 15 '12 at 19:48
  • Your implementation will be more accurate if you first look for the closest line segment (this may give a different result than looking for the closest points), which has been answered [here](http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment). Then you can compute the angle of the line segment using the line's vector and the function atan2, which you use for rotating the sprite. – coproc Oct 16 '12 at 05:56

1 Answers1

1

I implemented this, following coproc's advice. Unluckily, the code is a little to lengthy to post here, but you can read it and check it working online in wonderfl:

http://wonderfl.net/c/rYYU

Most relevant code lines are commented, the only assumption is that the house's graphic registration point is at its center (in my case I drew a Sprite, but it should work just as well with any MovieClip). I think it accomplishes quite well what you are looking for.

Hope this helps!

danii
  • 5,553
  • 2
  • 21
  • 23