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.
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.