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 ahomentc · Dec 17, 2014 at 09:52 PM · androidmovementtouchjump

GameObject won't jump with touch

When i drag my finger on the left side of the screen the gameobject moves according to the drag. But when i touch the right side of the screen(where the jump object is (invisible)) , then the gameobject stops and it doesn't jump. Can anybody help me?

 void Start () {
     posLine = GameObject.Find ("Main Camera").transform.position.x;
     rigidbody2D = GameObject.Find("player").GetComponent<Rigidbody2D>();
 }
 
 // Update is called once per frame
 void Update () {
     time ++;
     
 }
 
 void FixedUpdate(){
     for(int i=0; i< Input.touchCount;i++){
         
         if((Input.GetTouch(i).phase == TouchPhase.Moved || Input.GetTouch(i).phase == TouchPhase.Began || Input.GetTouch(i).phase == TouchPhase.Stationary))
         { 
             myRay = Camera.mainCamera.ScreenPointToRay(Input.GetTouch(i).position);
             {
                 if (Physics.Raycast(myRay, out rayHit ))    
                 {
                     if(rayHit.collider.tag == "move")
                     {
                         for (int ii = 0; ii < Input.touchCount; ++ii) {
                                 Touch touch2 = Input.GetTouch(ii);
                                     if (touch2.phase == TouchPhase.Began) {
                 touch1 = touch2.position.x;
         }
                             if (touch2.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Stationary) {
             if(touch2.position.x > touch1){
                 GameObject.Find ("player").transform.Translate (Vector3.right * moveSpeed * (Time.deltaTime) * 5);
             }
             if(touch2.position.x < touch1){
                 GameObject.Find ("player").transform.Translate (Vector3.left * moveSpeed * (Time.deltaTime) * 5);
             }
         }
                             
                         }
                     }

                     if(rayHit.collider.tag == "jump"){
                         if (time > 70) {
                             GameObject.Find ("player").rigidbody2D.AddForce (transform.up * jumpPower);
                             time = 0;
                         }
                     }
                 }
             }
             
         }
     }

 }

}

Thanks

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HYPERSAVV · Dec 18, 2014 at 02:15 AM

Start with adding a Debug.Log() statement in to at least verify that you are reaching that area of code. If you hit those statements you can assume your jump logic is sane. After that, try setting jumpForce to something crazy (ie. 5,000+)? I've often found that what I think should be a suitable amount of force is in fact no where near what it should be. Something else to try, pass ForceMode2D.Impulse as the second parameter to AddForce.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Replace Input.GetAxis with Touch 2 Answers

Swerve mechanic, Move left and right with touch 1 Answer

How to Move the Car With Touch? 1 Answer

How to touch, move and rotate 3D objects in XZ? 1 Answer

How do I move multiple 3D objects with Android touchscreen? 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