www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Miridian on January 10, 2011, 09:18:37 pm

Title: Need some help calculating angles of an onscreen joystick
Post by: Miridian on January 10, 2011, 09:18:37 pm
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: [Select]
//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);


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  :)
Title: Re: Need some help calculating angles of an onscreen joystick
Post by: Thomas. on January 10, 2011, 09:51:06 pm
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, ...
(http://i55.tinypic.com/2n8mxyo.png)
Title: Re: Need some help calculating angles of an onscreen joystick
Post by: Miridian on January 10, 2011, 10:08:29 pm
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

 
Title: Re: Need some help calculating angles of an onscreen joystick
Post by: Thomas. on January 10, 2011, 10:17:11 pm
You need some intelligent value from joystick, for example -128 to 128 from X and Y axises, where 0 is center...
Title: Re: Need some help calculating angles of an onscreen joystick
Post by: Miridian on January 10, 2011, 10:29:16 pm
I think I have found a dirty solution for my problem  ::)

Code: [Select]
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);
}
}

It works but if someone has a better solution I would be very happy :D
Title: Re: Need some help calculating angles of an onscreen joystick
Post by: Thomas. on January 10, 2011, 10:33:28 pm
you want to limit up/down angle?
PS: maybe something from this help you http://www.jpct.net/wiki/index.php/Main_Page