I am trying to drag a rigibody only the X axis. The code I have works fine! but I have found that the dragging does not have as swift as I like it.
I am wondering how it is possible to increase the sensitivity with the dragging of the sprite so that it responds faster to the drag and seems more ‘snappy’.
Here’ the code I am using right now to get the drag working on the X axis.
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
if(gameObject.GetComponent<Player>().startShooting == false){
gameObject.GetComponent<Player>().startShooting = true;
objManager.gm.startGame();
mainMenu.removeMenu();
gameScene.SetActive(true);
}
dragging = true;
mouseStartPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, -3, 0));
playerStartPos = gameObject.transform.position;
}
else if (Input.GetMouseButtonUp(0))
{
dragging = false;
}
if (dragging)
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, -3, 0));
mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x*Time.deltaTime, -3, 0));
Vector3 move = mousePos - mouseStartPos;
// gameObject.transform.position = playerStartPos + move;
GetComponent<Rigidbody2D>().MovePosition(playerStartPos + move);
}
}
}