- Home /
Question by
shubham112 · Jun 02, 2019 at 01:15 PM ·
touchaddforcejumping
How to do big jump when holding touch on mobile?
I searched it but couldn't find the complete solution to this. I am new to Unity so if you could provide with the coding then it would be really helpful. I want to jump and touch the screen and do a big jump when holding the touch. Here's the sample code of what i am trying :
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
// Handle finger movements based on TouchPhase
switch (touch.phase)
{
//When a touch has first been detected, change the message and record the starting position
case TouchPhase.Began:
// Record initial touch position.
if (onGround)
{
rb.velocity = new Vector2(rb.velocity.x, jump);
}
startTime = Time.time;
break;
case TouchPhase.Ended:
// Report that the touch has ended when it ends
realTime = Time.time - startTime;
Debug.Log(realTime);
if (realTime > 1.0f)
{
rb.velocity = new Vector2(rb.velocity.x, bigjump);
}
break;
}
}
I also am confused if I should use velocity or AddForce to jump, and why?
Comment
Your answer
Follow this Question
Related Questions
C# Screen.width Touch Input In Multiple Scripts Affect Each Other - Please Help 1 Answer
Why is my rigidbody jump height different every time, despite being in FixedUpdate. 1 Answer
How to make function respond to only the initial touch position. 1 Answer
Jumping problem to do with /= magnitude changing the vector3 direction 1 Answer