Question by
elifnurber · Oct 04, 2020 at 09:28 AM ·
mobiletouchmovement scripttouchscreenkeyboardmobile keyboard
I have touch codes for my mobile game but the character moves very slowly. Also my character doesnt jump. How can I solve it ?
void MovePlayerUsingTouch() { Vector3 goRight = new Vector3(0.50f, transform.position.y, transform.position.z); Vector3 goLeft = new Vector3(-3.45f, transform.position.y, transform.position.z);
if (Input.touchCount > 0)
{
Touch finger = Input.GetTouch(0);
if (finger.deltaPosition.x > 50)
{
right = true;
left = false;
}
if (finger.deltaPosition.x < -50)
{
right = false;
left = true;
}
if (finger.deltaPosition.y < 50)
{
rigi.velocity = Vector3.zero;
rigi.velocity = Vector3.up * jumpSpeed;
}
if (right == true)
{
transform.position = Vector3.Lerp(transform.position, goRight, moveSpeed * Time.deltaTime);
}
if (left == true)
{
transform.position = Vector3.Lerp(transform.position, goLeft, moveSpeed * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
Rotate object by touch using Angles? 0 Answers
Space Shooter Mobile Touch Controls Issue 1 Answer
How to make the "DragRigidBody" script mobile friendly? HELP! 0 Answers
Using Input.GetKey(KeyCode.Mouse0)) on iOS and Android 0 Answers
How to get the touch controls to work smooth and properly in FPS android gamemobile Game? 1 Answer