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 JDMorrison · Jan 19, 2014 at 06:45 PM · 2d-physicsjumping2d-gameplay

why player jumps forever

I have been watching the 2D Character Controllers tutorial. I set up everything like he did using my own sprites. I ran into a problem when adding jump. He adds a game object to detect ground which worked okay at first. I got the check mark when on the ground and when I fell, it went away. So I tried setting up jump with a blend tree to smooth animation. When I did this, some how player no longer detected the ground. Player would also jump with out me hitting space bar. He would also jump forever. So I changed the code and just made the animation normal. After that everything worked fine. This was at midnight last night. Saved closed everything and went to bed. When I got up everything I did was still the same. But When I hit play the player jumps again without hitting space bar forever. very strange and frustrating any help would be appreciated.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : MonoBehaviour 
 {
     public float jumpforce =700f;
     public float maxSpeed = 10f;
     bool faceRight = true;
 
     Animator anim;
 
 
 
     // Use this for initialization
     void Start () 
     {
         anim = GetComponent<Animator> ();
     
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
 
 
         anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
 
 
 
         float move = Input.GetAxis ("Horizontal");
 
         anim.SetFloat ("speed", Mathf.Abs (move));
 
         rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
 
         if (move > 0 && ! faceRight)
                         flip ();
                 else if (move < 0 && faceRight)
                         flip ();
     
     }
 
        void Update()
     {
         if( Input.GetKeyDown(KeyCode.Space));
         {
 
             rigidbody2D.AddForce(new Vector2( 0, jumpforce));
         }
     }
 
     void flip ()
     {
         faceRight = !faceRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
 
     }
 
 }
 

   
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Yusaku · Jan 19, 2014 at 07:56 PM

does the jump anuimation play forever or does the character continue to climb vertically forever?

Comment
Add comment · Show 3 · 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 JDMorrison · Jan 19, 2014 at 08:13 PM 0
Share

Both actually animation keeps looping and character goes up forever never falls.

avatar image JDMorrison · Jan 19, 2014 at 08:17 PM 0
Share

What is weird when I saved last night it worked! I have not changed anything since then. I thought it was the ground detection doing it. That is why I removed it and changed the code, to the way it is now. It worked but after closing and saving some how it revert back to doing the same thing.

avatar image Yusaku · Jan 19, 2014 at 08:37 PM 0
Share

Ok im pretty new at unity and development myself so I might just be missing something or maybe it not in this part of ur code but where are u implementing gravity? are you using rigid body gravity? ,ake sure if u are its still checked. You might try reloading your game too. Unity is wierd sometimes. I had a bit of harmless code the other day delete a mesh from my game. not an istance $$anonymous$$d you but the actual object had to reimport it.

avatar image
0

Answer by QuestionAsker · Jan 19, 2014 at 08:44 PM

I can't really tell too well whats going on, but I'd bet your issue is in lines 36-40 or your flip function. Or another script. Sometimes however, Unity acts weird and closing it all out, or even a restart will fix it. It's rare for an issue like that, but if it did infact work the night before, and you haven't changed anything, Id say reboot. It's happened to me. Good luck!

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

19 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

Related Questions

How can I improve 2D Jump? because it's sluggish 1 Answer

Jumping effectively in a 2D sidescroller 0 Answers

how to control amount of force taken from the surface 0 Answers

OnCollisonEnter2D. 1 Answer

2D Z-Levels HELP Needed! Can I script multiple objects to run on z levels,,2d Multiple Z levels in one scene 0 Answers


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