I have this code attached to a crosshair gameobject that is parented to the player in a top-down shooter. It is supposed to control the crosshair position on screen when using the right controller joystick to aim, however the crosshair sprite that is attached to the crosshair gameobject is vibrating a lot. I don’t know how to go about fixing this.
public class Crosshair : MonoBehaviour
{
private GameObject Player;
Vector2 ToPos;
public float RightHorizontalInput;
public float RightVerticalInput;
public float MaxDistance;
void Start()
{
Player = GameObject.FindWithTag("Player");
}
void Update()
{
RightHorizontalInput = Input.GetAxisRaw("RightStickHorizontal");
RightVerticalInput = Input.GetAxisRaw("RightStickVertical");
ToPos = new Vector2(Player.transform.position.x + (RightHorizontalInput * 10), Player.transform.position.y + (RightVerticalInput * 10));
transform.position = Vector2.MoveTowards(Player.transform.position, ToPos, MaxDistance);
}
}