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 Vanator · Jun 06, 2014 at 07:21 PM · charactercontrollerjump2dplatformer

2D box collider (character floating)

i have been reading other questions similar to this one, but none of them have worked for me, my problem is that my character seems to be floating and it cant jump since if not on ground, jump = false. Here are some screen, alt text the first one is before i run unity, the second one is when its running. alt text

I'm not sure if the size of the sprite has anything to do with it, since I´m using really small images (13x19). Any help is useful thx.

screen1.png (1.3 kB)
screen2.png (1.4 kB)
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 oasisunknown · Jun 06, 2014 at 08:50 PM 0
Share

Can we see your jump code there may be something in there that is setting some different values.

Also note t that if your character does not have a rigidbody he won't be affected by gravity and thus be pulled towards the ground.

Your sprite size itself should not have any effect because Unity is perfect ally happy just meshing different objects together in world space so if you put him in the ground Unity would say that's O$$anonymous$$ that's where you want him.

So it has to be something in your settings or in your code.

avatar image Vanator · Jun 06, 2014 at 10:15 PM 0
Share
 var onGround : boolean;
 private var jump : boolean;
 private var vm : float;
 var jumpSpeed : float = 25;
 var fallSpeed : float = 64;
 
 function FixedUpdate(){
           if(onGround && jump){ //Are we grounded can we jump?
                 vm = jumpSpeed;
                       }
           else {
                 
                 vm -= fallSpeed * Time.deltaTime;
                }
 vm = $$anonymous$$athf.Clamp(vm, -maxFallSpeed, maxUpSpeed); //Clamp vertical speeds
         rigidbody2D.velocity = Vector2.zero; //Stop movement if there is no input
         onGround = false; //Clear out grounding check

Also note t that if your character does not have a rigidbody he won't be affected by gravity and thus be pulled towards the ground. (Done).

Here is some part of the code (jump movement).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by oasisunknown · Jun 06, 2014 at 10:47 PM

Here are some things to note

 vm -= fallSpeed * Time.deltaTime; 

this does not need Time.deltaTime because your running it in fixed update. fixed update runs at a fixed step count and is not the same as the Update() function. Update runs as fast as the computer can go where FixedUpdate runs at a constant rate for physics reasons regardless of frame rate.

Next,

 rigidbody2D.velocity = Vector2.zero; //Stop movement if there is no input

This is constantly going to set your velocity to zero because it is run every time the FixedUpdate runs. encapsulate it in an if statement that says something like if not jumping then do this.

 onGround = false; //Clear out grounding check

I never see where you set this back to true. so in the code snippet its always false and always returns not grounded. Even if you set it to true in some other part of the code when it gets to it here it will just change it back to false.

Lastly I am going to link you to the Unity Learn tutorial that I watched about ground checks and jumping that Mike Geige did. He writes it in C# but the principles are the same.

The coding starts at around minute 38. everything before that is set up.

Unity Live Training Archive: 2d-controllers

Comment
Add comment · Show 3 · 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 Vanator · Jun 07, 2014 at 12:45 AM 0
Share

Gracias, this helped me get everything fixed.

avatar image oasisunknown · Jun 07, 2014 at 02:59 AM 0
Share

Glad to help.

avatar image underscorefrog · Jul 09, 2015 at 02:29 PM 0
Share

Please help, that script is outdated and I can't fix my problem!

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

22 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

Related Questions

can anyone help me to smooth the jump? 0 Answers

controller.Move not working correctly 0 Answers

tring to make a jump pad in fps 1 Answer

How animations are executed ?? 1 Answer

How to make a character controller jump properly 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