[Gambas-user] translating planar coordinates relative to point's angle
Doriano Blengino
doriano.blengino at ...1909...
Tue Mar 15 16:03:41 CET 2011
Kevin Fishburne ha scritto:
> On 03/14/2011 04:46 AM, Doriano Blengino wrote:
>
>> I think that you have too many variables involved... to define a speed
>> in a plane you need only two coordinates - you should choose between two
>> methods (or coordinate systems).
>>
>>
>> I think that you could choose by looking at what your joystick means to
>> you. Does it rotate the object, like the famous game Asteroids? Then
>> choose polar coordinates. Or does it mean left/right and up/down? Then
>> choose cartesian coordinates (but you talked about speed and direction...).
>>
>
> It actually does both, which is probably why it isn't working yet. I'm
> using a Playstation-style gamepad with two analog sticks for player
> control. The right stick's horizontal axis controls the player's
> orientation/direction and the left stick controls the player's
> movement/translation. Here's the breakdown of the two sticks:
>
> Right stick, left = Player turns counter-clockwise
> Right stick, right = Player turns clockwise
> Left stick, up = Player walks forward
> Left stick, down = Player walks backward
> Left stick, left = Player strafes left
> Left stick, right = Player strafes right
>
> It's very similar to the controls used in most first person shooters.
> Pushing the right stick modifies an orientation variable, so you can
> turn faster or slower depending on how far you push the stick. How far
> you push the left stick determines the speed with which you move.
> Combining the two sticks should allow things like circle-strafing.
>
By adding a fixed value to the orientation of the player, at every
frame, it will run in circle (speed<>0), or it will rotate on-place
(speed=0). The radius of the circle will be proportional to
speed/rotational_step...
> Based on what you said I'm guessing I should be using the second method,
> or is there something deeper I need to know?
>
I think there is nothing more to add... it depends on the real movements
of the player. When it strafes (never heard this term before - had to
consult a dictionary :-)) does it actually change its path? Perhaps no,
so the right joystick implements the movements of the player with polar
notation, while the left one creates missiles which, in turn, are moving
objects with a given speed and angle (polar again).
Polar and cartesian speeds could be combined too, anyway: in a single
frame you can add "polarspeed*cos(polarangle)" to Xpos,
"polarspeed*sin(polarangle)" to Ypos, then add "horizspeed" to Xpos and
"vertispeed" to Ypos. The result is again a vector with an angle, but
you can play with four variables... but I don't think this would lead to
an easy playable game (but you could use this to simulate the back-kick
of a heavy gun. Suppose the player is moving at 45° with speed 10; then
it fires at 135°. You could calculate back_kick_speedX=-cos(fired_angle)
and back_kick_speedY=-sin(fired_angle); then at every frame you move the
player in the usual manner, then add the components back_kick*, then
reduce the back_kick* components to 50% of before. This should simulate
a back-bump which quickly ceases :-)) ). This is not to insist on
Asteroids game, but it was actually behaving like this: the movement was
really in the x/y plane, with decreasing speeds, and when the fuel was
burned those x/y components were adjusted by sin and cos of the ship
orientation. In fact, it was hard to play... :-)
Cheers,
Doriano
More information about the User
mailing list