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 LelandGMC · Jun 05, 2015 at 04:11 PM · unity 5programming

2d Platformer Jump problems

I've been building the code to make the player jump

The issues were

  • The player jumps 2 times but locks up afterwards

  • The Player jumps continually instead jump twice then do thing again at any time

Here is the codes:

using UnityEngine;

using System.Collections;

public class Player : MonoBehaviour {

 //Stored Game Data - Private
 
 private bool facingRight = true;
 
 [SerializeField] private float Speed = 10f;
 [SerializeField] private float JumpStrength = 450f;
 
 [SerializeField] private bool airManipulate = false;
 
 
 //Stored Game Data 2- Private
   
 private bool grounded = false;
 private int jumpCounter = 0;
 
 void awake()
 {
  
 }
 
 private void FixedUpdate()
 {
  
 
     //// Reset double jump
     //if (grounded)
     //{
     //    doubleJump = false;
     //}
 }
 
 public void Movement(float move,  bool jump)
 {
     //Air Control
     if (grounded || airManipulate)
     {
         //Move the Character/Characters
         GetComponent<Rigidbody2D>().velocity = new Vector2(move * Speed, GetComponent<Rigidbody2D>().velocity.y);
 
         if (move > 0 && !facingRight)
             Flip();
         else if (move < 0 && facingRight)
             Flip();
        
     }
 
     //Disable double jumping after being used
      
    
 
    //Should the player to jump...
         if (grounded && jumpCounter !=0)
         {
             //grounded = true;
             //doubleJump = false;
             ////Reset vertical velocity when double jumping
             //GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
             jumpCounter = 0;
          
         }
         //Disable double jumping after being used
        
       if((grounded && jump) || (!grounded && jumpCounter < 2 && jump)){
 
                    
                             GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, JumpStrength));
                             grounded = false;
                             jumpCounter+=1;
                     }
        
    
    
 }
 
   
 
 private void Flip()
 {
     //Switch the way the player is labelled
     facingRight = !facingRight;
 
     //Multiply
     Vector3 theScale = transform.localScale;
     theScale.x *= -1;
     transform.localScale = theScale;
   
 }

}

And this is the one for PlayerControl:

using UnityEngine; using System.Collections;

 //It will need an Script "Player"
 [RequireComponent(typeof (Player))]

public class PlayerControl : MonoBehaviour {

 private Player character;
 private bool jump;
  

     private void Awake()
     {
         character = GetComponent<Player>();
     }
     private void Update()
     {

         if (Input.GetButtonDown("Jump"))
             jump = true;
          
     }
     private void FixedUpdate()
     {
      
         character.Movement(1, jump);
         jump = false;
                    
     }

}

Any suggestions on how to make the player jump twice without it locking up?

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How Can I Display UnityEvent in Custom Inspector When it is a Property of a Properties Property? (C#) 1 Answer

Problem with "Using Unity Standard Assets" in script C# 1 Answer

Need help in Stone throwing mechanic with aim in unity 3d C# 0 Answers

Hint Joint like a rope have weird behavior 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