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 Bincredible · Apr 02, 2013 at 08:50 PM · rigidbodyvector3addforcejumping

Character Jumping

Hello, I was wondering if there was a way to do jumping with a rigidbody. When I add a rigidbody to the player. When I click play, the player flies up into infinity and beyond. I am using this for the script so far :

 var JumpHeight : float = 8;
 
 function Update(){
 if(Input.GetKeyUp("space")){
 rigidBody.AddForce(Vector3.up * JumpHeight);
 }
 }

But this won't work because like I said before, the player flies up into the sky as soon as I play. Thanks in advance if anyone can help! :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by iwaldrop · Apr 02, 2013 at 09:20 PM

It sounds like your gravity might be inverted, or the rigidbody is interpenetrating into whatever it's sitting on, causing physics to freakout when you hit play and fire it off as if the two are colliding.

As an experiment, raise your player above ground level to see if he 'falls' in the correct direction. Also, you might try adding another floating rigidbody to the scene to see if the same thing happens. Also also, ensure you don't have any box colliders enveloping your character.

Gravity is set in Edit>Project Settings>Physics as a Vector3 at the top of the list of options. If it doesn't read -9.81 then it's been toyed with. It can read anything you want, of course, but if it's a positive number then that's why your character is taking flight.

Comment
Add comment · Show 4 · 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 Bincredible · Apr 03, 2013 at 12:34 AM 0
Share

The vector 3 I had : x was 0 y was -1000 z was 0 I changed y to -1 And now it works, but the jumping doesn't. :(

avatar image iwaldrop · Apr 03, 2013 at 12:39 AM 0
Share

When I play a game I expect to be able to smash a button and be able to hold it while jumping, but that's not going to stop it from working...

What might be wrong is the space being lowercase? I use c#, and is cs land you use a keycode for getkey. You might try using $$anonymous$$eycode.Space or "Space" ins$$anonymous$$d of "space".

avatar image Bincredible · Apr 03, 2013 at 10:43 AM 0
Share

Ok, I will try $$anonymous$$eyCode. :)

avatar image Bincredible · Apr 03, 2013 at 10:45 AM 0
Share

$$anonymous$$eyCode doesn't work. :(

avatar image
0

Answer by AronChan · Nov 06, 2013 at 07:24 PM

Try with this. (my code is c#)

 rigidbody.AddForce(jumpHeight, ForceMode.Impulse);

where jumpHeight is a vector3 (0, 12, 0)

You can play arround with the ammount to jump on the y-axis

also i recommend that you apply all your physics logic in the fixedUpdate() method instead of the normal update()

also you should probably check it on the Input.GetButtonDown("Jump") and set your jump in edit > input

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

12 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

Related Questions

Top Down car/vehicle movement 1 Answer

Jumping with rigid body3d 1 Answer

AddForce to a randomly selected GameObject with a rigidbody 0 Answers

Why is my rigidbody jump height different every time, despite being in FixedUpdate. 1 Answer

Why wont my character jump? (using rigidbody and addForce) 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