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 /
  • Help Room /
avatar image
0
Question by JebusChris · Apr 14, 2021 at 03:51 PM · inputjump

Character not jumping after switching to new input system

I am new to programming, and I am trying to make my character jump in a 2D platformer. I have switched to the new input system and now it will not jump with the code I used with the old system. I tried doing a Debug.Log to see if it is reacting to my button pressing, which it is. However, nothing else happens. Does anyone know why?

The code is as follows:

 [SerializeField] float runspeed = 5f;
 [SerializeField] float jumpSpeed = 15f;

 Inputs inputs;
 Rigidbody2D myRigidBody;
 Animator myAnimator;

 [SerializeField] LayerMask groundLayer;

 Vector2 direction;
 bool facingRight = true;
 public bool onGround = false;
 public float groundLength = 0.6f;



 private void Awake()
 {
     inputs = new Inputs();
     myRigidBody = GetComponent<Rigidbody2D>();
     myAnimator = GetComponent<Animator>();

     inputs.Player.Move.performed += ctx => direction = ctx.ReadValue<Vector2>();
     inputs.Player.Move.canceled += ctx => direction = Vector2.zero;
 }
 private void OnEnable()
 {
     inputs.Player.Enable();
 }


 private void OnDisable()
 {
     inputs.Player.Disable();
 }

  

 private void Update()
 {
     onGround = Physics2D.Raycast(transform.position, Vector2.down, groundLength, groundLayer);
     if(inputs.Player.Jump.triggered)
     {
         Jump();
     }
 }

 private void FixedUpdate()
 {
     Run();
 }

 private void Run()
 {
     Vector2 playerMovement = new Vector2(direction.x, 0) * Time.deltaTime;
     myRigidBody.MovePosition((Vector2)transform.position + (playerMovement * runspeed));
     myAnimator.SetFloat("horizontal", Mathf.Abs(direction.x));

     if((direction.x > 0 && !facingRight) || (direction.x < 0 && facingRight))
     {
         Flip();
     }

 }

 void Flip()
 {
     facingRight = !facingRight;
     transform.rotation = Quaternion.Euler(0, facingRight ? 0 : 180, 0);
 }

 void Jump()
 {
     if(onGround)
     {
         Vector2 jumpVelocity = new Vector2(0f, jumpSpeed);
         myRigidBody.velocity += jumpVelocity;
         Debug.Log("Test");
     }
 }

}

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

191 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 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 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 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 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

Jumping in Unity C# 2 Answers

Making a fly mechanic while using the same button for jump 0 Answers

Character Jump only works randomly and only with the "Y" Button 0 Answers

Jump does not work with diagonal movement. 1 Answer

Jump Input Problem 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