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 Supahtricia · Nov 19, 2015 at 07:13 AM · c#playercharactercontroller

I have possibly a silly qustion regarding 2d Player Jump input

I'm going along with a tutorial and all of my code is correct and it looks very similar to the asset of the 2DRobotBoy Asset. In my case for some reason my Player isn't jumping. Any advice or direction would be appreciated. In The meantime, I'm going to watch more tutorials to see how they applied jumping.

In my code I am actually using is grounded to detect the floor, In my scene I have it set to everything is ground. :)

Thanks in Advance!

This is my code:

using UnityEngine; using System.Collections;

public class PlayerController : MonoBehaviour { private Rigidbody2D myRigidBody;

 private Animator myAnimator;

 [SerializeField]
 private float MovementSpeed;

 private bool FacingRight;

 [SerializeField]
 Transform[] groundPoints;

 [SerializeField]
 private float groundRadius;

 [SerializeField]
 private LayerMask  whatIsGround;

 private bool isGrounded;

 private bool jump;

 //[SerializeField]
 //private bool airControl;

 [SerializeField]
 private float jumpForce;
 
 //adding a refrences
 // Use this for initialization
 void Start () {
     FacingRight = true; 
     myRigidBody = GetComponent<Rigidbody2D> ();
     myAnimator = GetComponent<Animator> ();
 }
 
 // Update is called once per frame
 void Update () 
 {

 }

 void FixedUpdate () 
 {
     float horizontal = Input.GetAxis ("Horizontal"); // looks at the input axis 

     isGrounded = IsGrounded();

     PlayerMovement (horizontal);

     Flip (horizontal);
     ResetValues ();
 }

 private void PlayerMovement( float horizontal )
 {

     myRigidBody.velocity = new Vector2 (horizontal * MovementSpeed, myRigidBody.velocity.y);


     myAnimator.SetFloat ("speed", Mathf.Abs (horizontal));

     if (isGrounded && jump) 
     {
         isGrounded = false;

         myRigidBody.AddForce(new Vector2(0,jumpForce));
     }
 }
 private void PlayerInput()
 
 {
     if(Input.GetKeyDown(KeyCode.W))
     {
         //myRigidBody.AddForce(new Vector2(0f,jumpForce));

         jump = true;
     }
 }



 private void Flip(float horizontal )
     {
         if (horizontal > 0 && !FacingRight || horizontal < 0 && FacingRight) 
         {

             FacingRight = !FacingRight;

             Vector3 theScale = transform.localScale;

             theScale.x *= -1;

             transform.localScale = theScale;
         }
         
     }
 private void ResetValues()
 {
 //attack =false
     jump = false;
 }

 private bool IsGrounded()
 {
     if (myRigidBody.velocity.y <= 0) 
     {
         foreach(Transform point in groundPoints)
                 
                 {  // colliders
             Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position,groundRadius,whatIsGround); 
             
             for (int i = 0; i < colliders.Length; i++)
             {
                 if (colliders[i].gameObject != gameObject)
                 {
                     return true;
                 }
                 
             }
         }
     }
         return false;
 }

}

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
Best Answer

Answer by _Game_Dev_Dude_ · Nov 19, 2015 at 08:56 AM

You are never calling the PlayerInput() function. Try putting it in your update or fixedupdate function and see what happens.

Comment
Add comment · Show 1 · 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 Supahtricia · Nov 19, 2015 at 05:48 PM 0
Share

I knew it was something silly!! Thank you for over looking this again for me.

It means a lot, thanks :3!!

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

41 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

Related Questions

Help on how to code crouching? 0 Answers

I want to add some Velocity controll to my CharacterController 1 Answer

Player does not jump? 0 Answers

Test for cube with tag "Player" touch cube with tag "Finish", then switch scene to "Lvl2" 0 Answers

Help with OnTriggerEnter Not working correctly? 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