- Home /
Tap for variable height jump, swipe to dash
Hi,
This may be a weird/interesting question. I'm currently working on a 2D, side scrolling, endless running game. Current touch input accounts for the following:
tap - jump swipe right - speed boost swipe down - drop to platform below
I've coded it so that my character can also do variable height jumping - meaning the longer the touch is held, the higher the character jumps - so I set the character to jump on touchphase.began.
Well the issues start when the player swipes right - the character will jump first, then dash (which makes sense since I'm also setting the character to jump on TouchPhase.Began. The best I've been able to do is cancel as much of the initial jump as possible by setting the rigidbody velocity to zero, then executing my dash code - but it looks awkward.
Any thoughts on how to approach this? I can't do tap detection on TouchPhase.End because the character won't jump until the player lifts their finger off the screen.
I've tried TouchPhase.stationary, but it's pretty iffy.
Any other thoughts?
Thanks in advance.
Answer by OrbitGames · May 12, 2014 at 06:36 PM
You can check for the the delta position on the first touch. If it is smaller than some number, than you jump, oterwise use swipe input.
This could be over sensible , so another option would be to jump once the finger is released, but it feels kind of awkward if the character doesn't jump immediately.
I would check after about two or three frames (you have to play around with this number) what the total deltaPosition is, so that is somewhat of a mixture of the two answers named above.
Thanks for your answer, I'll give it a try. How do you check "two or three frames" later?
Did you ever get an way out of it @antk? if u did, can you share with us please? (Talking about your main problem, to don't jump on swipes)
Your answer
Follow this Question
Related Questions
Custom touch phase? 0 Answers
Unity 2D. How to swipe without detecting tap? 2 Answers
Differentiating a tap from a swipe? 1 Answer
Single Tap Registered on Swipe (C#) 0 Answers
Detect whether a tap is a swipe up gesture or just a tap 0 Answers