- Home /
Question by
magarcan · Nov 29, 2012 at 10:33 AM ·
javascriptjoystickplaymaker
Joystick movement
Hi!
I'm using Penelope's Joystick.js script as a base. Here's the problem I've: http://youtu.be/gdsc8ZLP8OY
The problem is that the Joystick movement is squared instead of rounded. I've tried to fix it with this code:
// Get a value between -1 and 1
position.x = ( gui.pixelInset.x + guiTouchOffset.x - guiCenter.x ) / guiTouchOffset.x;
position.y = ( gui.pixelInset.y + guiTouchOffset.y - guiCenter.y ) / guiTouchOffset.y;
// Normalize code ;)
var angle : float;
angle = Mathf.Atan(position.y/position.x);
position.x = Mathf.Cos(angle);
position.y = Mathf.Sin(angle);
// Adjust for dead zone
Now the input is normalized between -1,1, but the desplacement of the graphics is still the same.
Any idea about how to fix it?
Cheers!
Comment