- Home /
Question by
Adygha · Aug 19, 2020 at 11:34 AM ·
velocityjumpaddforcedouble-tap
i couldnt make my object jump.,i couldn't make my object jump
when player doubletap on screen i want my object jump. i tried 3 different code but object doesnt jump. Is anyone can tell me why? I wrote code in lateupdate. i put debug.log and its working in same place.
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
{
tapCount++;
}
if (tapCount > 0)
{
doubleTapTimer += Time.deltaTime;
}
if (tapCount >= 2)
{
//rb.velocity = Vector3.up * force;
//rb.AddForce(transform.up * force);
rb.AddForce(new Vector3(0, 5f, 0), ForceMode.VelocityChange);
Debug.Log("doubletap successful");
doubleTapTimer = 0.0f;
tapCount = 0;
}
if (doubleTapTimer > 0.5f)
{
doubleTapTimer = 0f;
tapCount = 0;
}
Comment
The code looks fine to me. All that comes to $$anonymous$$d is the amount of force you’re adding there. Have you tried increasing that number to something really high just to see if the single frame add force is the problem? The force mode being velocity change will likely only disregard the rigidbody mass for that single frame, so having a much higher number than 5 might be the ticket.
Answer by blagwedge · Aug 19, 2020 at 11:46 PM
Instead of ForceMode.VelocityChange, use ForceMode.Impulse. That should sort it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613010020im_/https://answers.unity.com/themes/thub/images/avi.jpg)