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). > > The first one, which seems to fit best, is to choose a direction in > degrees (or radians) and a velocity. At ever"step", the x,y position > varies by cos(direction) and sin(direction), both multiplied first by > the velocity of the object. > > In the second method is to keep two velocities, left/right and top/down. > At every step, you add the velocities to the current position. > > As you see, both methods only involve two variables that specify the > direction and speed of the object, and of course its current position, > which get upgraded at every step (or frame). > > The first method, polar coordinates, is probably nearer to the idea of a > moving object. If the object changes direction, you simply change the > "direction" variable. If the object changes speed, you simply change the > "speed variable". > > The second method is the same as the former, where horizontal > (left/right) speed is cos(direction) and vertical is sin(direction). The > problem is that if you don't keep track of the "direction", but instead > you use its components, it is slightly difficult to change direction; > anyway, the two coordinate systems are the same, and from one you can > pass to the other at will (not counting math rounding problems).
Thanks, that is a very good explanation and gives me good food for thought. I'll try to apply it tonight to see if I can get things working properly. > 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. Based on what you said I'm guessing I should be using the second method, or is there something deeper I need to know? -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user