# How can I adapt the 2d joystic value to a 3d direction for the character?

Hello I am trying to move the character in joystick direction

Green arrow is what I am trying to get.

private void OnMovement(InputAction.CallbackContext obj)
{
if(obj.performed){
_MovementPoint = new Vector3(-obj.ReadValue<Vector2>().y, 0,obj.ReadValue<Vector2>().x ).normalized;
Debug.Log(this.transform.position);
}
}


And I am calling this on Update

 private void Update()
{
this.transform.position = this.transform.position + _MovementPoint*Time.deltaTime*6;
}


Is there a way?

• It's problem is it should rotation 45 angle ? Jul 5 at 9:38
• because your camera is 45 angle Jul 5 at 9:39
• @TimChang Yes that's what I am trying to do Jul 5 at 10:36
• @TimChang that worked thanks : newMovementDirection = Quaternion.AngleAxis(45, Vector3.up) * _MovementPoint; Jul 5 at 10:56

## 1 Answer

The screen coordinate system and the world coordinate system are different. You can convert the coordinates by Camera.ScreenToWorldPoint. Find the transformed vector by transforming two points:

void Update()
{
var p1 = Camera.main.ScreenToWorldPoint(Vector3.zero);
var p2 = Camera.main.ScreenToWorldPoint(_MovementPoint);
var moveDir = p2 - p1;
this.transform.position += moveDir * Time.deltaTime * 6;
}

• Thanks, I understand but this giving me a strange movement. Jul 5 at 10:35
• @AltC Hello, I found that _MovementPoint is on the x-z screen. Shouldn't it be on the x-y screen? Jul 5 at 10:39
• Hi, y is upward axis? so that's okay right Jul 5 at 10:45
• This worked for me : newMovementDirection = Quaternion.AngleAxis(45, Vector3.up) * _MovementPoint; Jul 5 at 10:56
• @AltC If you found a solution to your problem that differs from those give, I encourage you to write it up & post it as an answer. Jul 5 at 19:08