direction of joystick to control my character movements

im using NavMesh to control my character movements i set a target which the character will follow but now i only can move in the horizontal and vertical axis but not the diagonal axis here is my javascript i currently have;

private var joystickObj : GameObject;
private var joystick : Joystick; 
var target : Transform;// Set target forn player to move to
var agent : NavMeshAgent;

function Start() {
    joystickObj = GameObject.Find("Single Joystick");
    joystick = joystickObj.GetComponent(Joystick);
    agent = GetComponent(NavMeshAgent);

function Update() {

if (joystick.position.x > .5) {
       target.position = Vector3(transform.position.x + 2,transform.position.y,transform.position.z);
    else if (joystick.position.x < -.5) {
    target.position = Vector3(transform.position.x - 2,transform.position.y,transform.position.z);
    else if (joystick.position.y > .5) {
    target.position = Vector3(transform.position.x,transform.position.y,transform.position.z + 2);
    else if (joystick.position.y < -.5) {
    target.position = Vector3(transform.position.x,transform.position.y ,transform.position.z -2);



Of course you can only move in one direction. Look at your own code. Its 4 mutually exclusive ifs, one for each direction.

If you want to be able to read more then one at once remove the “else” from the start of each if clause.

All you need to do is remove the else ifs and replace them with just ifs. This way the program will take into account all possible movements in one update and will move as you want. THEN add if x and y is both moved move it so that x is moved up one and y is moved up one to move diagonally; add it for every possibility, enabling diagonal control.