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 JasonDN · Mar 25, 2014 at 10:14 PM · jumpbooleanboolcheckbox

Problem with jump bool. Help?!

I've got what seems like a decent movement script after following a tutorial, but there is just one problem that is really annoying me and I cannot figure out! I've tried several different things over the past couple days, stuff that I was certain would fix it.. until it didn't. My jump bool does not act like it should, or at least how I believe it should. Jumping itself seems to be fine, just the bool is acting funky. For instance, as it is now, if I jump the bool does not get checked, if I jump again while in the air it DOES get checked, then automatically jumps again once the player has landed. I just want it to get checked when I hit jump and then uncheck itself after, while the player is in the air, basically. Anyone see the problem in the code? Should I even worry about it since it seems to be working correctly other than the bool function and just go ahead and make it to where he can't jump while grounded?... Or what? Lol. I've racked my brain and I'm stuck. I know it's something simple.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(CharacterController))]    //This script requires a CharacterController
 
 public class Unit : MonoBehaviour 
 {
     protected CharacterController charController;    //Reference to the CharacterController
 
     protected Vector3 move = Vector3.zero;
 
     public float walkSpeed = 1f;
     public float runSpeed = 5f;
     public float turnSpeed = 90f;
     public float jumpSpeed = 5f;
 
     protected bool jump;
     protected bool running;
 
     protected Vector3 gravity = Vector3.zero;
 
     // Use this for initialization
     public virtual void Start () 
     {
         charController = GetComponent<CharacterController>();        //Assigns CharacterController to it's reference (charController)
 
         if (!charController)    //If there is no CharacterController attached..
         {
             Debug.LogError ("Unit.Start() " + name + " has no CharacterController!");    //..log error..    
             enabled = false;    // .. and disable the script.
         }
     }
     
     // Update is called once per frame
     public virtual void Update () 
     {
         if (running)
         {
             move *= runSpeed;
         }
         else
         {
             move *= walkSpeed;
         }
 
         if (!charController.isGrounded)
         {
             gravity += Physics.gravity * Time.deltaTime;
         }
         else
         {
             gravity = Vector3.zero;
 
             if (jump)
             {
                 gravity.y = jumpSpeed;
                 jump = false;
             }
         }
 
         move += gravity;
 
         charController.Move (move * Time.deltaTime);
     }
 }


 using UnityEngine;
 using System.Collections;
 
 public class UnitPlayer : Unit
 {
 
 
     // Use this for initialization
     public override void Start () 
     {
         base.Start();    
     }
     
     // Update is called once per frame
     public override void Update () 
     {
         //rotation
 
         transform.Rotate (0f, Input.GetAxis ("Turn") * turnSpeed * Time.deltaTime, 0f);
 
         //movement
 
         move = new Vector3(Input.GetAxis ("Strafe"), 0f, Input.GetAxis("Move"));
 
         move.Normalize();    //fixes diagnol movement speed
 
         move = transform.TransformDirection (move);        //makes player move in look direction
 
         if (Input.GetButtonDown ("Jump"))
         {
             jump = true;
         }
 
         running = Input.GetKey (KeyCode.LeftControl) || Input.GetKey (KeyCode.RightControl);
 
         base.Update();
     }
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

How can I do a foreach loop for an array of booleans? 1 Answer

Toggle bool with keypress -2 Answers

Boolean and input relation 0 Answers

I'm having trouble setting a bool. 2 Answers

GUI Tickbox (Boolean) 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