- Home /
How to use the Right stick of the controller like Input.mousePosition
void Update ()
{
if (Time.timeScale == 0)
{
} else
{
transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 10f));
}
}
}
Joystick is not a mousePosition, you need to use the input system, you can make a psuedomouse position like this.
public class CustomInput : $$anonymous$$onoBehaviour
{
private static CustomInput instance
{
get
{
if (_instance== null)
{
_instance = FindObjectOfType<CustomInput>();
}
return _instance;
}
private set
{
_instance = value;
}
}
private static CustomInput _instance;
public static Vector2 mousePosition
{
return instance._mousePosition;
}
private Vector2 _mousePosition;
public float mouseSpeed;
void Awake()
{
instance = this;
_mousePosition = new Vector2();
}
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
_mousePosition.x += h * speed * Time.deltaTime;
_mousePosition.y += v * speed * Time.deltaTime;
}
}
then you can use it like this.
void Update ()
{
if (Time.timeScale == 0)
{
} else
{
transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (CustomInput.mousePosition.x, CustomInput.mousePosition.y, 10f));
}
}
Of course you'll need to incorporate some code to prevent the position from being off screen, but that shouldn't be too difficult, heck you could use a UI canvas to detect if the point is in the RectTransform with RectTransformUtility.
is the same just take the chance that he is updating the position to store the progress?, also, is necessary ScreenToWorldPoint when you using GetAxis?
some kiss principle, please correct me if I just talking nosense
public float scaleDisplacement = 1;
void Update ()
{
if (Time.timeScale == 0)
{
} else
{
transform.position += new Vector3 ( Input.GetAxis("Horizontal") , Input.GetAxis("Vertical"), 10f/scaleDisplacement))*scaleDisplacement;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612191854im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating an app for mobile and browsers 1 Answer
Adapt OnMouseDown to control with Gamepad? 0 Answers
tags on ContactFilter2D? 0 Answers