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 /
avatar image
0
Question by EndsoftheEarth · Sep 14, 2016 at 12:30 PM · unity 2djumping

Why is my character jumping so fast?

So my sprite is jumping so fast it's practically at the point to where it's practically teleporting. I've fiddled with the code and the rigidbody so much, but it always has the same effect. Here's what my sprite looks like when jumping

Here's what how I want it to jump

Here's the entire code, with the jumping algorithm being in the Update() method

 private Animator myAnimator;

 private SpriteRenderer mySpriteRenderer;

 [SerializeField]
 private Rigidbody2D MyRigidBody;
 // Use this for initialization

 public float jumpPower;

 public float jumpTime;

 [SerializeField]
 private float moveSpeed;

 private float moveX = 0f;

 private float moveY = 0f;

 void Start ()
 {
     myAnimator = GetComponent<Animator>();
 }

 public void Awake()
 {
     mySpriteRenderer = GetComponent<SpriteRenderer>();
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     moveX = Input.GetAxis("Horizontal");
     MyRigidBody.velocity = new Vector2(moveX * moveSpeed, 0);
     if (Input.GetKey(KeyCode.D))
     {
         myAnimator.SetBool("RunRight", true);
     }
     else
     {
         myAnimator.SetBool("RunRight", false);
     }

     if (Input.GetKey(KeyCode.A))
     {
         myAnimator.SetBool("RunLeft", true);
     }
     else
     {
         myAnimator.SetBool("RunLeft", false);
     }

    
 }


 void Update()
 {
     if (Input.GetKeyDown(KeyCode.W))
     {
             MyRigidBody.AddForce(new Vector2(0, jumpPower));
     }
 }

I've tried putting the jumping code in FixedUpdate() and it didn't make a difference. I've fiddled with the gravity, and jump power, and I still have no idea what I'm doing wrong. Please help, thanks.

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 Sergio7888 · Sep 15, 2016 at 01:39 AM 0
Share

Check you animation speed in the animator.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Adarn · Sep 16, 2016 at 04:02 AM

First thing to avoid is doing physics related changed in update. The physics engine is intended to be changed from FixedUpdate. The reason for this is that FixedUpdate will be called once per physics step. (That's the physics engine equivalent of a frame). Not a major problem just something to consider.

Now as for the fast jump.

The problem will be in HOW you are applying the jump force. There are 2 ways that you can applying a force to a RidgedBody2D.

One is as a force. (This is what you are doing)

The second is as an Impulse. This is how you will normally want to make a RidgedBody "jump".

The difference is in how the physics engine applies the force. An impulse is applied as an instant change in velocity where as a force is more like a push.

Because in a game we expect "jumping" to be instant (otherwise it doesn't feel "right") we need the force to be applied instantly. This is what ForceMode2d.Impulse is for.

What you are currently doing is pushing the RidgedBody up. Now in order to do this you will be applying a MASSIVE force to make it look instant. The down side of this is you have just pushed your ridged body so hard that it is going to take a long time for the gravity force to contract your force.

Now I am assuming that you have something checking for the top of your jump to prevent your Body from flying of into space. If you use an impulse you will probably find you no longer need this as you will get the nice jump arc you are looking for naturally.

You will also be able to use a smaller jump force. Just play around with your values till it feels right.

The change you want to make is this

 MyRigidBody.AddForce(new Vector2(0, jumpPower), ForceMode2D.Impulse);
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

my jump key works about once every 10 presses 1 Answer

trying to get a good wall jump for my 2d game 1 Answer

Grounded check not working on sloped ground. 1 Answer

Jumping while moving on the x axis being weird 1 Answer

2d Character won't jump 2 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