A
A
Artem Brjinski2022-03-27 17:15:41
Mobile development
Artem Brjinski, 2022-03-27 17:15:41

How to set the movement of the player using swipes?

Hello everyone, I watched a video on how to make player movements using swipes and on the video the person doesn’t have exactly what I need, he uses the Vector3.MoveTowards method that moves the player a certain distance, but I need something to say, when swiping up an object moved continuously up, until the moment you make a swipe to the left, after that it stops moving up and starts moving towards the swipe, that is, to the left. How to do this, or what is the best method to do this? Many thanks in advance!
This is the code of the movement itself from the author of the video *

public float moveSpeed;
    private Vector3 targetPosition;

    private void Start() 
    {
        targetPosition = transform.position;
    }

    public void Move(Vector3 moveDirection)
    {
        targetPosition += moveDirection;
    }

    private void FixedUpdate() 
    {
      transform.position = Vector3.MoveTowards(transform.position, targetPosition, moveSpeed * Time.deltaTime);
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question