0

I am making a game, using a onscreen/virtual joystick. The joystick it self works fine.

What I want is when you turn the joystick, a bullet is fired in that direction. I got that working too. Now the problems arises when shooting a bullet when the joystick is not at the edge/radius.

When the joystick is at the edge/radius, the bullet move at maximum speed, exactly what I want. But when the joystick is, lets say, somewhere between the radius and the center of the joystick, the bullets move slower. This is logical because of the radians and stuff.

But it is not what I want. What should happen is that the bullets always move at the maximum speed.

Does anyone know how this could be achieved? I am completely stuck at this.

Thanks!

EDIT: since I still dont understand this at all, basically what I want is that I have a point in radians within a circle and I want to get the position of that point at the edge of the circle.

So let's say I have this Vector2 in radians.

    Vector2(-0.3, 0.3);

and the radius of the circle is 40.

The length from the center of the circle to the Vector2 point would propably be somewhere around

    radius = 40 * 0.3 = 12

Now what would the Vector2 point be when the length is 40?

I can't seems to figure this out. Trigonometry is definetely not my strongest point.

DijkeMark
  • 1,284
  • 5
  • 19
  • 41
  • 2
    Clamp the speed to the max speed, you can find this by the magnitude of the line from the center point i'd imagine, hard to say without code – Sayse Aug 28 '13 at 21:13
  • I get your idea, but I got now idea how to do that. I added some info, could you take a look again? – DijkeMark Aug 29 '13 at 19:20
  • 1
    The magnitude is pythagoras - square root of Difference in the x's squared plus difference of y's squared, sorry hard to type on phone – Sayse Aug 29 '13 at 20:57
  • Yes, the magnitude is not the problem. But how can this magnitude help me with getting the position on the edge of the circle? – DijkeMark Aug 29 '13 at 21:06
  • 1
    you need the [angle from the center of the circle](http://stackoverflow.com/questions/7586063/how-to-calculate-the-angle-between-two-points-relative-to-the-horizontal-axis), then use this to determine a velocity i think – Sayse Aug 29 '13 at 21:17

1 Answers1

0

I fixed it! I just multiplied to localPosition of the joystick with a very large number, so that the localPosition woul fall outside of the radius. Then I just use clampMagnitude to get it at the edge of the radius. Now I get the correct behaviour.

DijkeMark
  • 1,284
  • 5
  • 19
  • 41