jPCT-AE - a 3d engine for Android > Support

Need some help calculating angles of an onscreen joystick

(1/2) > >>

Miridian:
Hi, I have started writing my first java project a few days ago.
It is a small game where I am using an onscreen joystick to turn the player.
I already have the joystick and the player but I cant find out how to turn the player by the angle of the joystick.

Code:


--- Code: ---//get the angle
//initx,inity is the start point of the joystick
//touchingPoint is the point where the finger is touching the screen.
angle = Math.atan2(touchingPoint.y - inity,touchingPoint.x - initx);

//rotate the player
player_mesh.rotateY((float) (jpctaetest.controls.getAngle()/10)* ft);

--- End code ---


I think it am using the wrong way for the angle because my player mesh is rotating slow when the joystick is on the right side and very fast when it is on the left  ???
please help  :)

Thomas.:
I used also virtual joystick in my game... I rotate SimpleVector and camera by joystick and move camera by this SimpleVector...
cam.rotateCameraAxis(cam.getYAxis(), -rotateX);
camDir.rotateY(-rotateX);

But it is very alpha version without textures, ...

Miridian:
Yes it is the same what i am trying to get for my game.
Can you please help me to get a correct value from the joystick?
My object is rotating but in the wrong way and speed   :D

 

Thomas.:
You need some intelligent value from joystick, for example -128 to 128 from X and Y axises, where 0 is center...

Miridian:
I think I have found a dirty solution for my problem  ::)


--- Code: --- float ft = (float) ticks;
double test = jpctaetest.controls.getAngle();
if (!(Math.toDegrees(test) == 0)) {
if (Math.toDegrees(test) < -90 || Math.toDegrees(test) > 90) {
player_mesh.rotateY((float) (Math.toRadians(1)) * ft);
} else {
player_mesh.rotateY((float) (Math.toRadians(1) * -1) * ft);
}
}

--- End code ---

It works but if someone has a better solution I would be very happy :D

Navigation

[0] Message Index

[#] Next page

Go to full version