Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 darkal · Jul 12, 2018 at 08:16 AM · movementinputcharactercontrollerjumping

My player keeps launching into the sky

So the code is made and everything works except for jumping which i really need to get fixed so issue is when player is walking up hills or going up stairs and etc if you jump you launch into the sky and pretty much glide your back down.

 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour{
     [HideInInspector]
     public bool sprinting;
     [HideInInspector]
     private Rigidbody selfRigidbody;
     [HideInInspector]
     public Option menukey;
     [HideInInspector]
     public KeyController ControllerCS;
     [HideInInspector]
     public bool isGrounded;
 
     void Start()
     {
         selfRigidbody = GetComponent<Rigidbody>();
     }
     void Update()
     {
         if (!menukey.MenuLock)
         {           
             for (int i = 0; i < ControllerCS.KeyCS.Length; i++)
             {
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Sprint")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         sprinting = true;
                     }
                     else
                     {
                         sprinting = false;
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Forward")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key) && sprinting)
                     {
                         transform.Translate(0, 0, 6f * Time.deltaTime);
                     }
                     else if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(0, 0, 3f * Time.deltaTime);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Back")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(0, 0, -3f * Time.deltaTime);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Right")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(3f * Time.deltaTime, 0, 0);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Left")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(-3f * Time.deltaTime, 0, 0);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Jump")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key) && isGrounded)
                     {
                         selfRigidbody.AddForce(0, 25, 0, ForceMode.Impulse);
                         isGrounded = false;
                     }
                 }
             }
         }
     }
 
     void OnCollisionStay()
     {
         isGrounded = true;
     }
 }
 
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 Shameness · Jul 12, 2018 at 08:33 AM 0
Share

Hi. What is your expected behaviour, should it jump less or it should go forward while jumping ? $$anonymous$$y understanding so far your character just moves forward using transform translate, however, you can still climb because characters rigid-body pushed up by terrain or stairs. Could this be root of your unexpected behaviour ?

avatar image darkal Shameness · Jul 12, 2018 at 08:42 AM 0
Share

issue is that if i jump on incline the isGrounded bool I am guessing remains true and due to key being pressed it preforms a double jump or more, sending my characters higher into the air so i basically need help in figuring out how prevent that issue from reoccurring. I've tried yield and wait for seconds before and it did kinda work but there was still cases the issue would still occur.

avatar image Shameness darkal · Jul 12, 2018 at 08:50 AM 0
Share

See if Q&A below helps:

https://answers.unity.com/questions/196381/how-do-i-check-if-my-rigidbody-player-is-grounded.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by darkal · Jul 12, 2018 at 08:51 AM

The issue i found out was i had jump key set as getkey rather than a getkeydown after changing it to proper one and adjusting the the force of the jump the script works fine but thankyou anyway.

 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour{
     [HideInInspector]
     public bool sprinting;
     [HideInInspector]
     private Rigidbody selfRigidbody;
     [HideInInspector]
     public Option menukey;
     [HideInInspector]
     public KeyController ControllerCS;
     [HideInInspector]
     public bool isGrounded;
 
     public float jumpforce;
 
     void Start()
     {
         selfRigidbody = GetComponent<Rigidbody>();
     }
     void Update()
     {
         if (!menukey.MenuLock)
         {           
             for (int i = 0; i < ControllerCS.KeyCS.Length; i++)
             {
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Sprint")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         sprinting = true;
                     }
                     else
                     {
                         sprinting = false;
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Forward")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key) && sprinting)
                     {
                         transform.Translate(0, 0, 6f * Time.deltaTime);
                     }
                     else if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(0, 0, 3f * Time.deltaTime);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Back")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(0, 0, -3f * Time.deltaTime);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Right")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(3f * Time.deltaTime, 0, 0);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Left")
                 {
                     if (Input.GetKey(ControllerCS.KeyCS[i].AllKeys.key))
                     {
                         transform.Translate(-3f * Time.deltaTime, 0, 0);
                     }
                 }
                 if (ControllerCS.KeyCS[i].AllKeys.keyname == "Jump")
                 {
                     if (Input.GetKeyDown(ControllerCS.KeyCS[i].AllKeys.key) && isGrounded)
                     {
                         selfRigidbody.AddForce(0, jumpforce, 0, ForceMode.Impulse);
                         isGrounded = false;
                     }
                 }
             }
         }
     }
 
     void OnCollisionStay()
     {
         isGrounded = true;
     }
 }
 
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

158 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 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 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 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 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 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 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 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

Gradual Speed Increase with Variable Input 0 Answers

Two near-identical scripts cause a cat to jump in different ways - why? 2 Answers

How do I make a jumping and ledge-grabbing system, similar to TLoZ OOT in unity 3d? 0 Answers

How to keep current velocity while jumping? 0 Answers

Movement with AddForce: Wrong Direction 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