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 /
This question was closed Jul 24, 2013 at 09:28 PM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Keavon · Nov 06, 2010 at 05:41 AM · jumpmoveuptornado-twins

Help wanted -- How to make my character jump (using slightly modified Tornado Twins move script)

Hello. Here is my script:

var speed = 3.0; var rotateSpeed = 3.0; var bullitPrefab:Transform; var bullitspeed = 2000000; private var dead = false;

function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; } }

function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);

     if(Input.GetButtonDown("Fire1"))
     {
         var bullit = Instantiate(bullitPrefab, GameObject.Find("FireballSpawnPoint").transform.position, Quaternion.identity);

         bullit.rigidbody.AddForce(transform.forward * bullitspeed);
     }
 }

 function LateUpdate()
 {
     if(dead)
     {
         transform.position = Vector3(20, 4, 20);
         gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
         dead = false;
     }
 }


@script RequireComponent(CharacterController)

I need to add a jump function. I tried myslef, but it kept failing. Help would really be appreciated (I want to use space as jump) Thanks!!! :D

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

5 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by superventure · Dec 21, 2010 at 02:15 AM

Set the button you want by going to edit> project settings> input.

after that>>

set a var like : var jumpSpeed = 10;

    if (Input.GetButton ("Jump")) 
    if (controller.isGrounded){
    moveDirection.y= jumpSpeed;

You may also need to set up gravity

// Apply gravity moveDirection.y -= gravity * Time.deltaTime;

// Move the controller controller.Move(moveDirection * Time.deltaTime);

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 Keavon · Dec 30, 2010 at 03:35 AM 0
Share

Thank you, I will try it soon. :P

avatar image
0

Answer by fireDude67 · Dec 21, 2010 at 02:48 AM

To do it with the physics system:

  • Attach a Rigidbody component (Component > Physics > Rigidbody)
  • Add the following code to jump:

    var jumpSpeed = 10;

    function Update() { if (Input.GetKeyDown(KeyCode.Space)) { rigidbody.AddRelativeForce(0, jumpSpeed, 0); } }

    Another way to do it would be to use a character controller (Component > Physics > Character Controller)

    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 Keavon · Dec 30, 2010 at 03:35 AM 0
    Share

    Thank you, I will try it soon. :P

    avatar image
    0

    Answer by NumbedShot · Jan 10, 2011 at 04:16 PM

    For the T_T Tutorial the space bar is going to be used to shoot fireballs, keep that in mind.

    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 Keavon · Jan 11, 2011 at 04:15 AM 0
    Share

    Yes, I changed that to click though.

    avatar image
    0

    Answer by ant123 · Jun 18, 2011 at 01:33 PM

    I tried both these scripts just now, first one didnt jump, second one didnt compile!

    will have a nap and then see why!

    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 naruto · Jun 19, 2011 at 03:47 PM

    add a var "jumpSpeed" then in your Update function add this

             if(Input.GetButtonDown("Jump")){
             if (controller.isGrounded){
               moveDirection.y = jumpSpeed;
              }
           
          }
          
          // Apply gravity
          moveDirection.y -= movement.gravity * Time.deltaTime;
    
          // Move the controller
          controller.Move(moveDirection * Time.deltaTime);
    
    

    so your script should look something like this

     var speed = 3.0;
     var rotateSpeed = 3.0;
     var jumpSpeed : float = 5.0; 
     var bullitPrefab:Transform;
     var bullitspeed = 2000000;
     private var dead = false;
     
     function OnControllerColliderHit(hit : ControllerColliderHit)
     {
         if(hit.gameObject.tag == "fallout")
         {
             dead = true;
         }
     }
     
     function Update ()
         {
             var controller : CharacterController = GetComponent(CharacterController);
             transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
             var forward = transform.TransformDirection(Vector3.forward);
             var curSpeed = speed * Input.GetAxis ("Vertical");
             controller.SimpleMove(forward * curSpeed);
     
     
             if(Input.GetButtonDown("Fire1"))
             {
                 var bullit = Instantiate(bullitPrefab, GameObject.Find("FireballSpawnPoint").transform.position, Quaternion.identity);
     
                 bullit.rigidbody.AddForce(transform.forward * bullitspeed);
             }
             
             if(Input.GetButtonDown("Jump")){
                 if (controller.isGrounded){
                   moveDirection.y = jumpSpeed;
                  }
               
              }
              
              // Apply gravity
              moveDirection.y -= movement.gravity * Time.deltaTime;
     
              // Move the controller
              controller.Move(moveDirection * Time.deltaTime);
             
         }
     
         function LateUpdate()
         {
             if(dead)
             {
                 transform.position = Vector3(20, 4, 20);
                 gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
                 dead = false;
             }
         }
      
           @script RequireComponent(CharacterController)
    
    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

    Follow this Question

    Answers Answers and Comments

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    Natural Jump algorithm 2 Answers

    How to get global up vector? 1 Answer

    Player Controls 0 Answers

    "Hover" object up and down 2 Answers

    Control Mid-Air Movement With Character Controller 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