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 Pathojen · Nov 10, 2021 at 08:57 PM · rigidbody3dpc

Cannot Jump or fall while while moving?

Hello, all. I have been working on making my player character jump, and he jumps fine as long as he is not moving. If he is moving, however, ie I am pressing the keys to move him, he slowly ascends, seemingly ignoring gravity or the amount of force the Rigidbody added until I stop pressing the keys and he descends as desired. After I make him jump while idling, I can make him stay in the air by walking around, which is also undesirable. I don't recall ever experiencing this before.

Here's a section of the code so far.

 public class PlayerScript : MonoBehaviour
 {
 
     public Animator Anim;
     public Rigidbody RBody;
 
     public float speed = 3f;
     public float horizontalSpeed = 2.0f;
     public float verticalSpeed = 2.0f;
     public float jumpForce = 2.0f;
 
 
 
     public Vector3 jump;
     void Update()
     {
         float h = horizontalSpeed * Input.GetAxis("Mouse X");
         transform.Rotate(0, h, 0);
         transform.Translate(0, 0, speed * Input.GetAxis("Vertical") * Time.deltaTime);
         Anim.SetFloat("speed", Input.GetAxis("Vertical"));
 
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Jump();
         }
     
     void Jump()
     {
         jump = new Vector3(0.0f, 2.0f, 0.0f);
         RBody.AddForce(jump * jumpForce, ForceMode.Impulse);
     }
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 unity_ka6jgzfPPmtNCw · Nov 11, 2021 at 04:53 AM 0
Share
 transform.Translate(0, 0, speed * Input.GetAxis("Vertical") * Time.deltaTime);

With this line, you're telling it to stay in the same posisiton with the exception of your vertical input. If you want physics to be applied, stop overriding it by using transform to move your gameObject.

2 Replies

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

Answer by Pathojen · Nov 11, 2021 at 11:37 PM

Whoa...easier than I thought. Just add the jump function before the move function, apparently. It works like a charm.

 void Update()
 {
     if (Input.GetButtonDown("Jump") && isGrounded == true)
     {
         Jump();
     }
     //MovePlayer();
 }

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 swanne · Nov 10, 2021 at 09:29 PM

Hey,
Get rid of the Vector3 jump.
Replace your Jump() function with this

 void Jump()
          {
              RBody.AddForce(0.0f, jumpForce, 0.0f, ForceMode.Force);
          }

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 Pathojen · Nov 10, 2021 at 11:37 PM 0
Share

Had trouble with the code but finally got it working. Trouble is it does exactly what $$anonymous$$e does. I will keep digging for answers.

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

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

Throwing a Spear 1 Answer

Grappling hook springjoint 0 Answers

How can I add smooth movement to a RigidBody? 2 Answers

Calculate Angular Velocity to Match Remote Position 0 Answers

How to move player on a moving vehicle 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