- Home /
Question by
yousseffotouh2013 · Jul 27, 2021 at 11:54 AM ·
dragcontrolsrunner
Runner Game : Smooth Right Left Movement Control
I'm trying to implement runner controls like in modern runner games in the mobile stores , such as : "Hair Challenge" or "Fat to Fit!".
Unlike the classic movement of swiping from left to right or vice versa , the movement is more of a drag now where the player moves with the user's touch instantly.
I tried to achieve this , but the result movement is weird , where the player moves only to the right and in unreliable manner.
My code :
void Update()
{
if (Input.GetMouseButton(0))
{
dist = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, startPos.z));
var v3 = dist;
v3.y = transform.position.y;
v3.z = transform.position.z;
transform.position = Vector3.Lerp(transform.position, v3, Time.deltaTime*0.05f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Simultaneous Touch Drag Controls 0 Answers
How to flick an object on mobile devices 3 Answers
click vs long press (drag) help? 1 Answer
How do I re-enable input after dragging off iPad screen? 0 Answers