Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by arvidowic · Jul 08, 2020 at 09:34 AM · objectjumping

I`m not able to jump

Hi everyone. I followed this YouTube tutorial (link text) to get touch inputs for my game but for some reason I am not able to jump. Can anybody help me how to fix it?`enter code here`

using System.Collections; using System.Collections.Generic; using UnityEngine; public class MobileInput : MonoBehaviour {

 private const float DeadZone = 100.0f;

 public static MobileInput Instance { set; get; }

 private bool tap, swipeLeft, swipeRight, swipeUp;
 private Vector2 swipeDelta, startTouch;

 public bool Tap { get { return tap; }  }
 public Vector2 SwipeDelta { get { return swipeDelta; } }
 public bool SwipeLeft { get { return swipeLeft; } }
 public bool SwipeRight { get { return swipeRight; } }
 public bool SwipeUp { get { return swipeUp; } }


 private void Awake()
 {
     Instance = this;
 }

 private void Update()
 {
     // Reseting booleans
     tap = swipeLeft = swipeRight = swipeUp = false;

     // Input

     if (Input.touches.Length != 0)
     {
         if (Input.touches[0].phase == TouchPhase.Began)
         {

             tap = true;
             startTouch = Input.mousePosition;
     }
     else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled)
     {
             startTouch = swipeDelta = Vector2.zero;
     }
 }

     // Calculate Distance
     swipeDelta = Vector2.zero;
     if (startTouch != Vector2.zero)
     {
         // Check with mobile
         if(Input.touches.Length != 0)
         {
             swipeDelta = Input.touches[0].position - startTouch;
         }
     }

     // Check if you are beyond the deadzone
     if (swipeDelta.magnitude > DeadZone)
     {
         // Confirmed Swipe
         float x = swipeDelta.x;
         float y = swipeDelta.y;

         if(Mathf.Abs(x) > Mathf.Abs(y))
         {
             // Left or Right
             if (x < 0)
                 swipeLeft = true;
             else
                 swipeRight = true;
         }
         else
         {
             //Up or Down
             if (y > 0)
                 swipeUp = true;
         }

         startTouch = swipeDelta = Vector2.zero;
     }
 }

}

If that doesn´t help you I could also send my player controller script. You just need to ask. Thanks in advance!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BonusB · Jul 08, 2020 at 09:38 AM 0
Share

What does the error say?

avatar image arvidowic BonusB · Jul 08, 2020 at 09:39 AM 0
Share

nothing, I just can´t jump.

avatar image arvidowic BonusB · Jul 08, 2020 at 09:41 AM 0
Share

I also added an animation which works when I swipe up but the player is not jumping.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ray2yar · Jul 08, 2020 at 12:04 PM

If it's detecting the action in the animator then your problem is likely in whatever script controls the actual character movement. Don't see any code here that would change a character's position.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image arvidowic · Jul 08, 2020 at 12:54 PM 0
Share
  private float jumpForce **strong text**= 2.0f;
  private float gravity = 8.0f;
  private float verticalVelocity;
 
 if(isGrounded)
         {
             verticalVelocity = -0.1f;
 
             if ($$anonymous$$obileInput.Instance.SwipeUp)
             {
                 verticalVelocity = jumpForce;
                 anim.SetTrigger("Jump");
             }
             else
             {
                 verticalVelocity -= (gravity * Time.deltaTime);
             }
    Here is my player jumping code.
 
avatar image arvidowic · Jul 08, 2020 at 01:19 PM 0
Share

Ok, got the mistake. But thanks for your help!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My jump code seems to be broken, the character's flags for jumping appear to be working strangely. 1 Answer

How to add collider to a Torus object 5 Answers

How can I move an object to preset list of locations, on a path, with control over rotation, translation and speed? 0 Answers

Problems with the instantiation of a GameObject C# 1 Answer

NullReferenceException: Object reference not set to an instance of an object ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges