- Home /
Help with jump
I have a script and i am trying to get the cube to jump on a swipe up, can some one point me in the right direction, thanks
function Update()
{
var tap = false;
var swipeUp = false;
var swipeDown = false;
if(Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began ||
((touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
&& fingerDownTime <=0))
{
fingerDownTime = Time.time;
fingerDownPos = touch.position;
}
else if (touch.phase == TouchPhase.Ended)
{
if((touch.position.y - fingerDownPos.y) > swipeThreshhold)
swipeUp = true;
else if((touch.position.y - fingerDownPos.y) < -swipeThreshhold)
swipeDown=true;
else
tap = true;
fingerDownTime = -1;
}
}
var horizontal = Input.GetAxis("Horizontal");
horizontal += -Input.acceleration.y * accelerometerScale;
trans.Rotate(0,rotateSpeed * horizontal * Time.deltaTime ,0);
if (character.isGrounded && Input.GetKeyDown(KeyCode.Space) || tap)
Pedal();
var moveDirection = trans.forward * speed;
moveDirection += Physics.gravity;
character.Move(moveDirection * Time.deltaTime);
if(character.isGrounded)
{
if(speed < 0.3)
speed = 0;
else
{
speed -= decayRate * Time.deltaTime * speed;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613081449im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Jumping Problem? 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I Javascript swipe to move my first person? 1 Answer
Swipe Control Issue.. Need help 1 Answer
IOS Swipe Gesture 0 Answers