Disable mouse movement

I am receiving values over udp using the below code and want the gameobject to move using these values only along the x axis… but using following code gameobject only moves on mouse movement.
I am getting values over udp sockets. I just want to move the gameobject using these values only and not using mouse or keyboard…I am not able to get how to do it…

    Vector3 originalPosition = cam.ScreenToWorldPoint(Input.mousePosition);
    Vector3 targetPosition = new Vector3 (originalPosition.x, this.transform.position.y, 0.0f);
    float xmove = Input.GetAxis("Horizontal")* Time.deltaTime * speed;
    float targetWidth = Mathf.Clamp (targetPosition.x, -maxWidth, maxWidth);
    targetPosition = new Vector3 (xmove,targetPosition.y,targetPosition.z);
   
      GameObject HatSprite = GameObject.Find ("HatSprite");
       ReceiveLeft = HatSprite.GetComponent<UDPDualReceive>().lastReceivedLeft;
       ReceiveRight = HatSprite.GetComponent<UDPDualReceive>().lastReceivedRight;
      transform.position = targetPosition;

i want to use lastReceivedLeft and lastReceivedRight to move the gamobject…

your transform position is based on targetPosition which is based on mouse position according to your script. I don’t see any link between ReceiveLeft, ReceiveRight and the transform position in your code. Maybe you must do something like this:

Vector3 pos = new Vector3(xmove, ReceiveLeft, ReceiveRight);

Something like that…

Not sure why you’d receive a left and a right :wink: That seems silly, since one can imagine you could combine them (unless they are sent from different people or something).
If left comes as a negative, and right as a positive, just add 'em up

transform.position = new Vector3((left+right),targetPosition.y,targetPosition.z);
1 Like