Player movement like in crowd city

Hi,
I want to control my player (single object) in same "swipe in ∞ " manner as in the game Crowd city by Voodoo. I have only got this far and the motion doesn’t seem on point, also the player stops at point when the device is continuously touched, I want it to keep moving till it goes out of screen.

 public class PlayerControl : MonoBehaviour
{
    private Vector2 finalPos;
    private Vector3 finalTouch;
    public new Rigidbody rigidbody;
    private bool isMoving = false;
    void update()
    {
        foreach (Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Began)
            {
                finalPos = Input.mousePosition;
                isMoving = true;
            }

            if (touch.phase == TouchPhase.Moved)
            {
                finalPos = Input.mousePosition;
                isMoving = true;
            }

            if (touch.phase == TouchPhase.Ended)
            {
                finalPos = Input.mousePosition;
                isMoving = true;
            }

            if (touch.phase == TouchPhase.Stationary)
            {
                isMoving = false;
            }
        }
        if (isMoving)
        {
            Ray finalRay = Camera.main.ScreenPointToRay(finalPos);
            RaycastHit hit_touch;
            if (Physics.Raycast(finalRay, out hit_touch, Mathf.Infinity))
            {
                finalTouch = new Vector3(hit_touch.point.x, 0.75f, hit_touch.point.z);
            }
            Ray mouseRay = new Ray(finalTouch, finalTouch - gameObject.transform.position);
            if (mouseRay.direction.x != 0 && mouseRay.direction.y != 0)
            {
                rigidbody.velocity = new Vector3(mouseRay.direction.x * 5, 0, mouseRay.direction.z * 5);
            }
        }
    }
}

Can you describe what you want without asking people try some other game first?

2 Likes

I want player to keep moving moving in a direction with constant speed, the direction changes with drag direction. Also it should keep moving to the previous direction if the screen is just touched or touch is long pressed (stationary).
As shown in screenshot attached user drags to give direction to players, meanwhile the speed of player is constant. So far with above script I can control with player with drag but drag threshold is too much and I don’t think that it is the correct way to do so.

5409105--549333--Screenshot_20200126-115623.jpg