- Home /
Question by
Aladine · Apr 19, 2018 at 02:18 AM ·
rotationjoysticktouchscreen
touchscreen/Mouse joystick movement in 2d
Hello,
I am trying to make a movement exactly like this but on 2D :

what i made so far :
// move forward
transform.Translate(Vector3.up * forwardSpeed * Time.deltaTime);
Vector3 target = new Vector3(0, 0, Mathf.Atan2(direction().x,direction(). y) * Mathf.Rad2Deg);
euler.z = Mathf.LerpAngle(euler.z, target.z, 5 * Time.deltaTime);
transform.eulerAngles = euler;
Vector3 direction()
{
Vector3 dir = Vector3.zero;
Vector3 firstPos = Vector3.zero;
Vector3 currentPos = Vector3.zero;
if (Input.GetMouseButtonDown(0))
{
firstPos = Input.mousePosition;
currentPos = firstPos;
}
if (Input.GetMouseButton(0))
{
currentPos = Input.mousePosition;
}
//
dir = currentPos - firstPos;
return dir;
}
but the result is not exactly what am looking for.
any help please ?
Comment
Your answer
Follow this Question
Related Questions
Rotating game object using UI Joystick 0 Answers
No movement to negative z-axis. 1 Answer
advanced problem for me regarding transfering rotation from the gizmo to the object 0 Answers
Rotate Locally Player Towards Joystick/Axis Input 1 Answer
How can i rotate 3D object with joystick in all directions? 0 Answers