1 Reply Latest reply on Sep 25, 2008 9:10 AM by Newsgroup_User

    Using a virtual joystick to control a characters moves

    Bob220867 Level 1
      Okay so I'm using the mouse to control a virtual joystick onscreen that then moves a character. I'm using this code below to generate the direction and it works fine when restricted to up/down and side to side moves but I want to a)move diagonally and b) make sure the character is correctly rotated in the direction of the move.

      Below is the code I'm using where I generate an angle from the start (pStartPos) and current (my.loc) positions of the control knob.

      dx=my.locH-pStartPosH
      dy=my.locV-pStartPosV
      ang = atan( dy, dx ) * 180 / PI
      angleDegrees = ang + 180

      So I want to understand (maybe that's a tall order but...) how to convert my outcome to relative horizontal and vertical movements and how to set the rotation for that.

      I never did trig the first time round so this is from a standing start...

      Thanks.
        • 1. Re: Using a virtual joystick to control a characters moves
          Level 7
          Bob220867 wrote:
          > dx=my.locH-pStartPosH
          > dy=my.locV-pStartPosV
          > ang = atan( dy, dx ) * 180 / PI
          > angleDegrees = ang + 180
          >
          > So I want to understand (maybe that's a tall order but...) how to
          > convert my outcome to relative horizontal and vertical movements and
          > how to set the rotation for that.
          >
          > I never did trig the first time round so this is from a standing
          > start...

          It isn't clear to me exactly what you're asking, but...

          x=r cos(t)
          y=r sin(t)

          where r is the distance from (0,0) and t (you'll often see it as the Greek
          letter theta) is the angle anti-clockwise from the x-axis.

          Remember, Director's y-axis is upside-down compared to the convention in
          maths, so positive and negative angles go the non-conventional way.

          More info:
          http://en.wikipedia.org/wiki/Polar_coordinates

          HTH

          Andrew