Swipe control smoothness problem
Hello,
I've set up my swipe controls to transform my player left/right/up/down and I've restricted the movement on 3 lines; -1, 0, 1. Everything works fine but the movement is not smooth at all and the player seems to be "teleporting" from one position to another. I wanted to smooth the movement by playing the animation but the result was that the animation was being played after the player has changed his position. Is there any way to play the animation while the player is changing his position or a way to smooth the movement so it looks right ?
I've tried everything and now I'm stuck with the problem, please help
Here's my code
public class SwipeControls : MonoBehaviour
{
public float speed = 5.0f;
private Vector3 startpos; // start position
private Vector3 endpos; //end position
public int pozioma = 0;
public int pionowa = 0;
Animator anim;
void Start()
{
GetComponent<Animator>();
}
void Update()
{
foreach (Touch touch in Input.touches)
{
Vector3 newPosition;
if (touch.phase == TouchPhase.Began)
{
startpos = touch.position;
endpos = touch.position;
}
if (touch.phase == TouchPhase.Moved)
{
endpos = touch.position;
}
if (touch.phase == TouchPhase.Ended)
{
newPosition = transform.position;
if (Mathf.Abs(startpos.y - endpos.y) > Mathf.Abs(startpos.x - endpos.x))
{
if ((startpos.y - endpos.y) > 100 && pionowa > -1) //swipe down
{
pionowa--;
newPosition.y -= speed;
transform.position = newPosition;
anim.SetTrigger("Flydown");
}
if ((startpos.y - endpos.y) < -100 && pionowa < 1) //swipe up
{
pionowa++;
newPosition.y += speed;
transform.position = newPosition;
anim.SetTrigger("Flyup");
}
}
else
{
if ((startpos.x - endpos.x) > 100 && pozioma > -1) //swipe left
{
pozioma--;
newPosition.z -= speed;
transform.position = newPosition;
anim.SetTrigger("Flyleft");
}
}
if ((startpos.x - endpos.x) < -100 && pozioma < 1) //swipe right
{
pozioma++;
newPosition.z += speed;
transform.position = newPosition;
anim.SetTrigger("Flyright");
}
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612195557im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Black Scrreen after Splash Screen after deploy on HoloLens 1 Answer
Loot table problems 1 Answer
Game crashes on iPhone 11 0 Answers
Need help with Mute Button 1 Answer