I’m working on a top down 2d game (like pokemon or stardew valley) for mobile use. I’m trying to make a player movement script that moves the player to the position being touched on screen, but for some reason my player always moves up and to the right. It’ll change direction somewhat based on where I’m, but always some version of up and to the right. If someone could shed some light on what might be causing this, I’d be very grateful. I’ve included the script I’m using, and would be happy to include more info if it helps, just lmk. Thank you for any help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Began)
{
Vector2 pos = touch.position;
transform.position = Vector3.MoveTowards(transform.position, pos, moveSpeed * Time.deltaTime);
}
}
}
}