2D Character movement using OnDrag
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
Your answer
Follow this Question
Related Questions
How to create a movement script for my person by controlling him by joystick 0 Answers
Buttons for Player movement 0 Answers
All object move together when try to drag one object only 0 Answers
My character carries on the run animation for a few seconds even after standing still 0 Answers
Drag and drop Dress up 1 Answer