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 Bioshok7 · Sep 15, 2017 at 02:20 PM · 2dgravityjumpingplatformerfalling

Problem of gravity

Good afternoon,

I am currently developing ,me only, a 2d platformer video game,

I use as player , cat asset bought with it animations on spriter pro steam and then transferred with the spriter pro tool to unity ,

This player (cat asset spriter pro) measures on unity 2 meters . 56 cm approximately (2 units . 56) in length includes these ears (I use several polygons collider for each parts of the cat body assembled afterwards with a composite collider with automatic mass , density equal 1 and no physic material 2d),

from the beginning of the development of my project, I always encounter a problem of gravity and acceleration of gravity which influence in an wrong level design and the other parameters of controller movement like jump force value, move force value and run force value ,

and the jump curve was always in the shape of a triangle acute , even with low gravity , with any value of move or run force,

and the jump or fall had a gravity too slight,regardless of the length of the fall,   I asked also before this question on the forum (see this link)   link text   and I had an answer, it partially corrected these problems, but not completely,   after this topic and acutally, the jump curve is correct (half circle) with some values ​​of move force for each value of gravity,

but the problem is that I attribute the gravity value very roughly without any precision or logic behind,

with initial gravity on y value between -50 and -100 and is always incorrect

(not satisfied with these values ​​because the fall is always slightly slow and not fast as desired despite these abnormally high gravity values)

and with move force which becomes more fast than necessary for these values ​​of gravity to keep the shape of semi-circular jump curve,

not to mention the acceleration of gravity which is low and slow for short falls like the simple jump and on the contrary too fast for a large (the greater the fall, the faster the speed of gravity increases) even for a gravity value of only 15,   otherwise I also noticed that there are no great differences between gravity value of 15 and 100 for the jump,

(all these parameters such as gravity, move force, jump force, run force are apparently linked and the variation of one will affect the others)   here is a part of the source code of the project (that of jumping and moving),

  void FixedUpdate ()
             {           
                          if ((!Input.GetKey (KeyCode.RightArrow) && !Input.GetKey (KeyCode.LeftArrow)) && Input.GetAxis ("L_XAxis_1") == 0 && Input.GetAxis ("DPad_XAxis_1") == 0) {
                                     h = 0;
                              rigidBody.velocity = (new Vector2 (h, rigidBody.velocity.y));
                                     wait = true;
                                     anim.SetFloat ("speed", 0f);
                         } else if (!Input.GetKey (modes.boutonX) && !Input.GetKey (KeyCode.Joystick1Button1)) {
                                   if (Input.GetKey (KeyCode.RightArrow) || Input.GetAxis ("L_XAxis_1") > 0 || Input.GetAxis ("DPad_XAxis_1") > 0) {
                                         h = 1;
                                        anim.SetFloat ("speed", 1f);
                                     }
                                  if (Input.GetKey (KeyCode.LeftArrow) || Input.GetAxis ("L_XAxis_1") < 0 || Input.GetAxis ("DPad_XAxis_1") < 0) {
                                         h = -1;
                                         anim.SetFloat ("speed", 1f);           
                                     }
                                     wait = false;
                                  rigidBody.velocity = (new Vector2 (h * moveForce, rigidBody.velocity.y));    
                                     anim.SetBool ("X", false);    
                          } else if (Input.GetKey (modes.boutonX) || Input.GetKey (KeyCode.Joystick1Button1)) {        
                                     if (!toJump) {      
                                  if (Input.GetKey (KeyCode.RightArrow) || Input.GetAxis ("L_XAxis_1") > 0 || Input.GetAxis ("DPad_XAxis_1") > 0) {
                                             h = 1;
                                             anim.SetFloat ("speed", 1f);
                                         }
                                  if (Input.GetKey (KeyCode.LeftArrow) || Input.GetAxis ("L_XAxis_1") < 0 || Input.GetAxis ("DPad_XAxis_1") < 0) {
                                             h = -1;
                                             anim.SetFloat ("speed", 1f);     
                                         }
                                         wait = false;
                                  rigidBody.velocity = (new Vector2 (h * maxSpeed, rigidBody.velocity.y));
                                         anim.SetBool ("X", true);
                                     }
                                 }
                             Jump ();   
             }
         void Jump ()
             {           
          if (Input.GetKeyDown (modes.spaceButton) || (Input.GetAxisRaw ("Jump") > 0 && jump)) {
                     if (jumpOk) {
                         if (jumpNumber >= 0) {      
                             jumpNumber--;
                             up = true;           
                             toJump = true;                 
                          rigidBody.velocity = new Vector2 (rigidBody.velocity.x, jumpForce);                      
                             jump = false;
                         }
                     }
                 }    
          if (Input.GetAxisRaw ("Jump") == 0 && !Input.GetKeyDown (modes.spaceButton)) {                 
                     jump = true;     
                 }
             }

how to correct completely this problem please and what are all the exact values ​​for my character (move force, force force, jump force, gravity value, density, mass etc)   ?.

Thank you very much ,

Cordially .

Comment
Add comment · Show 2
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 jmgek · Sep 13, 2017 at 10:52 PM 0
Share

Please trim your code to only include the core problem. No one wants to read 130 lines to understand your problem.

avatar image Bioshok7 · Sep 16, 2017 at 01:09 PM 0
Share

up please

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bioshok7 · Sep 17, 2017 at 06:35 AM

up please

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

131 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

Related Questions

Advice needed on my first c# 2D jump script 1 Answer

2D Sidescroller enemy AI jump help! Picture Included! 3 Answers

Change gravity on button 1 Answer

Why does Gravity (Physics2D) produce different results for AddForce() versus velocity in player sprite? 2 Answers

2D Platformer Jump while Running Android 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