- Home /
Question by
boldrebel · Apr 24, 2017 at 02:50 PM ·
android2d gamecontrollermobile devicesdrag-and-drop
Problem in character movement
Hello everyone, i am developing a game which is designed for android, and the character can move from dragging the controller, and the controller is on top of the character's head. Lets say we are dragging the controller on the right, the character pointer will point on left, and dragging on top left moves the pointer to the right bottom and so on. After releasing the controller, the character goes to the current location of the pointer.
these are the instance variables:
public float dt;
public float res;
and these are the codes inside the OnDrag Method
dt = (bdy.rectTransform.rect.width)*1.00f;
res = (Mathf.Atan2 (yz, xz) * Mathf.Rad2Deg);
if (res >= -22.55 & res <= 22.55) {
vn3 = new Vector3 (GameObject.Find ("Body").transform.position.x + (xn = -dt)
, GameObject.Find ("Body").transform.position.y
, GameObject.Find ("Body").transform.position.z);
this.transform.position = vn3;
}
res is a float variable that receives the angle of the controller. the problem is the distance of the character move is not dynamic as screen size changes.
Thank you :)
untitled3.png
(53.8 kB)
Comment