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 DiegoBurgrito · May 13, 2019 at 08:54 AM · jumpingcapsulecollider

Capsule Collider stays on floor when my character jumps

Whenever my character jumps its capsule collider stays on floor while he goes into the air. I am new to all this so can someone explain how to fix this issue and what do i have to change in my script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Player_Controler : MonoBehaviour
 {
     public bool isGrounded;
     public bool isCrouching;
 
     private float speed;
     private float w_speed = 0.05f;
     private float r_speed = 0.1f;
     private float c_speed = 0.025f;
     public float rotSpeed;
     public float jumpHeight;
     Rigidbody rb;
     Animator anim;
     CapsuleCollider col_size;
     
 
     // Start is called before the first frame update
     void Start() { 
         rb = GetComponent<Rigidbody>();
         anim = GetComponent<Animator>();
         col_size = GetComponent<CapsuleCollider>();
         isGrounded = true;
     }
     
 
     // Update is called once per frame
     void Update() {
       
 
         //Toggle Crouch
         if (Input.GetKeyDown(KeyCode.LeftControl))
         {
             if (isCrouching)
             {
                 isCrouching = false;
                 anim.SetBool("isCrouching", false);
                 col_size.height = 2;
                 col_size.center = new Vector3(0, 1, 0);
             }
             else
             {
                 isCrouching = true;
                 anim.SetBool("isCrouching", true);
                 
                 speed = c_speed;
                 col_size.height = 1;
                 col_size.center = new Vector3(0, 0.5f, 0);
             }
         }
 
         var z = Input.GetAxis("Vertical") * speed;
         var y = Input.GetAxis("Horizontal") * rotSpeed;
 
         transform.Translate(0, 0, z);
         transform.Rotate(0, y, 0);
         
         if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
         {
             rb.AddForce(new Vector3(0, 3, 0), ForceMode.Impulse);
             anim.SetTrigger("isJumping");
             anim.SetBool("isCrouching", false);
             isCrouching = false;
             isGrounded = false;
         }
         
         if (isCrouching)
         {
             //Crouching Controls
             if (Input.GetKey (KeyCode.W))
             {
                 anim.SetBool("isWalking", true);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", false);
             }
             else if (Input.GetKey(KeyCode.S))
             {
                 anim.SetBool("isWalking", true);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", false);
             }
             else
             {
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", true);
             }
         }
         else if (Input.GetKey(KeyCode.LeftShift))
         {
             speed = r_speed;
             //Running Controls
             if (Input.GetKey(KeyCode.W))
             {
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isIdle", false); 
                 anim.SetBool("isRunning", true);
             }
             else if (Input.GetKey(KeyCode.S))
             {
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isIdle", false);
                 anim.SetBool("isRunning", true);
             }
             else
             {
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", true);
             }
         }
         else if (!isCrouching)
         {
             speed = w_speed;
             //Standing Controls
             if (Input.GetKey(KeyCode.W))
             {
                 anim.SetBool("isWalking", true);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", false);
             }else if (Input.GetKey(KeyCode.S))           
             {
                 anim.SetBool("isWalking", true);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", false);
             }else
             {
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isRunning", false);
                 anim.SetBool("isIdle", true); 
             }
         }
 
     }
     void OnCollisionEnter(Collision col)
     {
         if (col.gameObject.tag == ("Ground") && isGrounded == false)
         {
             isGrounded = true;
             
         }
     }
 }
 

Comment
Add comment · Show 1
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 tormentoarmagedoom · May 13, 2019 at 11:48 AM 0
Share

Can you post screenshots of inspector? of the object?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EternalClickbait · May 13, 2019 at 10:30 AM

Make sure the collider is attached to the same object as the script and rigidbody

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

107 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

Related Questions

How can I stop the fps controller jumping up slopes? 1 Answer

Character Controller / Charactor Motor has no inputs? 1 Answer

please help me!!!!!!!!!!!!!!!!!!!! 2 Answers

Rigidbody, jumping and gravity help 0 Answers

How do I create variable Jump Height for a platformer? 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