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 JJDeveloper · Jul 18, 2014 at 09:33 AM · javascript3djumpjumping

3D Game-Making a character jump

I've tried various ways. I can make my character go up, just not come back down. Also, I want that acceleration effect when jump, so it looks lees like walking upward. The only way I can think of doing it would be too primitive for Unity, which is adding collision for each object, and using some sort of time or jump height for coming back down. ANy help appreciated, or better yet, some snippet of javascript jump code. I would prefer not to use the axis, and just jump from the "ground" my character is on. Here's some code snipped:

 var controller : CharacterController = GetComponent(CharacterController);
         if (controller.isGrounded){
             //if(Input.GetKey(KeyCode.Space)){
                 //transform.Translate(Vector3.up * jumpSpeed * Time.deltaTime); 
                 //transform.position += transform.up * jumpSpeed * Time.deltaTime;
             //}
             if (Input.GetKeyDown ("space")){
                 transform.Translate(Vector3.up * jumpSpeed * Time.deltaTime, Space.World);
          } 
         }

Comment
Add comment · Show 3
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 Josh Naylor ♦♦ · Jul 18, 2014 at 09:34 AM 0
Share

Please format your code.

avatar image robertbu · Jul 18, 2014 at 02:00 PM 0
Share

If you are using a CharacterController, see the sample script in the reference for CharacterController.$$anonymous$$ove() and ChacterController.$$anonymous$$oveSimple(). Both implement jump using a character controller.

avatar image Zodiarc · Jul 18, 2014 at 02:11 PM 0
Share

You could add velocity in y direction to the rigidbody. This way the character will go up and through the gravity the velocity will be smaller until it reaches 0 and goes below it which will cause it to fall down.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RedOneDigitals · Jul 18, 2014 at 03:23 PM

Hi!

check this video it may help you:

https://www.youtube.com/watch?v=wbrFLqV51rQ

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 Bojidar · Jul 18, 2014 at 03:24 PM

Using Zodiarc's coment:

 var controller : CharacterController = GetComponent(CharacterController);
 if (controller.isGrounded){
     if (Input.GetKeyDown ("space")){
         rigidbody.AddForce (Vector3.up);
     } 
 }

For this to work, you need to have a rigidbody(3d) attached to your character.

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 Fearthefrozt · Jul 18, 2014 at 04:20 PM 0
Share

And just a side note make sure to have gravity on after you add the rigidbody, otherwise the character will never come down!

avatar image
0

Answer by sixShOOter50o0 · Jul 19, 2014 at 07:23 PM

add this to the code:

 var customGravity : float = 10;
 var isGrounded : boolean = true;
     
 function Update()
 {
     if(isGrounded == false)
     {
         transform.position -= Vector3.up * customGravity * Time.deltaTime;
     }
 
     if(isGrounded)
     {
         //do nothing
     }
 }
 
 function OnCollisionStay ()
 {
     isGrounded = true;
 }
 
 function OnCollisionExit()
 {
     isGrounded = false;
 }


what this basically does is that if you are not grounded (on the floor) you will apply an opposite force on the y axis which is gravity; and when you are on the floor it will do nothing. in small words you are just emulating gravity. I have not tried this script so i do not know if it will work. you may have a bug that gravity won`t apply when you are touching a wall or anything else that is vertical.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I have a problem with my jump script 1 Answer

3D coyote time 1 Answer

character controller wont rise when I Jump :( 1 Answer

How do I make my character jump? 1 Answer

How to position the jump animation with the object's body? 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