Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 jacques 1 · Apr 19, 2011 at 12:39 AM · jumpjumpingsimpleeasy

making a jump button

hey people what is a simple code for jumping with shift

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 MC HALO · Apr 19, 2011 at 12:50 AM

var jump : float = 4f;

function Update (){

if(Input.GetKey(KeyCode.LeftShift)){

//rigidbody.velocity = Vector3(0 ,jump,0 ); rigidbody.AddForce(Vector3.up * jump);

}

}

you can use //rigidbody.velocity = Vector3(0 ,jump,0 ); or // rigidbody.AddForce(Vector3.up * jump); its up to you. This is how i would make a simple jump using rigidbody :)

hope this helps

Ok this is the Updated script, this one does not require any rigidbody it only needs a character controller. But just to let you know you don't even need to add a character controller to the player because the script will add it automatically :) once the script is added.

The script will also allow you to walk up and down using the vertical key "A, D" and using the Horizontal keys " W , S " you can rotate the player. to make sure it is working make the camera the child of the object :)

anyway's here is the script:

private var moveDirection = Vector3.zero;

     private var grounded : boolean = false;

         var gravity = 20.0;

             var JumpSpeed : float = 10;

               var rotatespeed : float = 5;

                  var speed : float = 10;

      function Update () {


var controller : CharacterController = GetComponent (CharacterController);

                  //Rotate around y -axis

  transform.Rotate(0, Input.GetAxis ("Horizontal") * rotatespeed, 0);

              //move forward / backwords Vertical

                   var forward =  transform.TransformDirection(Vector3.forward);

                           var curSpeed = speed * Input.GetAxis ("Vertical");

                                              controller.SimpleMove(forward * curSpeed);

     if(grounded){

             if (Input.GetButton("Jump")){

                             moveDirection.y = JumpSpeed;





                     }   
                 }
                 moveDirection.y -= gravity * Time.deltaTime;

                     var flags = controller.Move(moveDirection * Time.deltaTime);

                                 grounded = (flags & CollisionFlags.CollidedBelow) != 0;
              }

              @script RequireComponent(CharacterController)

Comment
Add comment · Show 6 · 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 jacques 1 · Apr 19, 2011 at 02:26 AM 0
Share

it says unknown identifier: 'jump'.

avatar image MC HALO · Apr 19, 2011 at 03:37 AM 0
Share

Ops sorry i forgot a variable :) updated the script :)

avatar image jacques 1 · Apr 19, 2011 at 10:19 PM 0
Share

is there anything i can do without rigidbody

avatar image MC HALO · Apr 20, 2011 at 12:13 PM 0
Share

yea there is you can use character controller i will update it for you so you can have the player jump with the character controller ins$$anonymous$$d :)

avatar image jacques 1 · Apr 21, 2011 at 01:26 AM 0
Share

how can i get rid of bounce, because i jump then bounce bounce bounce for a while and it shakes the camera and looks terrible

Show more comments
avatar image
0

Answer by Rafaelski · Oct 12, 2020 at 11:59 PM

bool jump = CrossPlatformInputManager.GetButtonDown("Fire 3");

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

1 Person is following this question.

avatar image

Related Questions

How do I script so my character Jumps farther when Running? 1 Answer

Player Character looses jump height the further right they go 1 Answer

Jumping effectively in a 2D sidescroller 0 Answers

jump with character controller best way? 1 Answer

Im trying to make it so it limits jumps in my 2d game. But when I play it, It only jumps once then your not able to jump again. Anyhelp? I need a answer fast because this is for the blackthornprod game jam 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