Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by XaenSai · Feb 24, 2016 at 12:53 PM · c#scripting problem2d gameplatformer

Jump Script

I am currently having issues with a jump script as you can see with the code below, I have tried many variations of the code and still no success, the issue i am having is that the character jumps up and down way too fast and when you press the space bar after an initial jump it continues to jump.

 using UnityEngine;
 using System.Collections;

 public class Jumping: MonoBehaviour {

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     Jump ();
     
 }

 void Jump ()
 {
         if (Input.GetKeyDown ("space")) {
         
             transform.Translate (Vector3.up * 130 * Time.deltaTime);
         }
      
     }

 }
Comment
Add comment · Show 1
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 Ali-hatem · Feb 24, 2016 at 03:35 PM 0
Share

make a bool variable and test if true then jump and when player jump set it false and for the jump speed just increase or decrease 130

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jgodfrey · Feb 24, 2016 at 05:06 PM

You'll need to have some notion of your character being "grounded" (on the ground). This can be done via collision events, trigger events, etc. Once you know that your character is on the ground, you can allow a jump. However, once the character has jumped, you'll want to not allow another jump until the character becomes grounded again (typically done with a boolean variable). Unless, of course, you want to allow a double-jump. In that case, you could allow one additional jump before requiring the character to be grounded again.

None of the above is overly difficult to do, but is too broad to simply provide code for. You should work on the various pieces mentioned above and ask more specific questions as you run into trouble.

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
avatar image
0

Answer by XaenSai · Mar 03, 2016 at 02:06 PM

@jgodfrey

I have attempted to modify the script further but i wish to extend this so that it checks if the player is grounded, how would i go about this ? improved code below.

 using UnityEngine;
 using System.Collections;

 public class Jumping: MonoBehaviour {

 public Vector2 velocity;
 public Vector2 speed;
 bool jump;
  

 
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     Jump ();
     
 }

 void Jump ()
 {
     jump = false;
     if (!jump)
     {
         if (Input.GetKeyDown ("space"))
         {
             jump  = true;
             transform.Translate(Vector3.up * 75 * Time.deltaTime);
         }
     }
     /*else
     {
         //jumping is true.
         //Check to see if player is on the floor.
         if (PlayerOnFloor())
         {
             jump = false;
         }
     }*/

 }

}

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C#: How do you make a 2D game object jump? 1 Answer

Can somebody help me fix this script? 2 Answers

Why does it say The type or namespace 'BoardManager' could not be found. Are you missing 'Completed' using directive? 1 Answer

Help! Values from previous Serialized List<> shows up again after a while using Coroutine 0 Answers

Help! Create interactive button with an image + c# Script 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