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 /
  • Help Room /
avatar image
0
Question by Kyle_Nichol · Nov 19, 2018 at 09:05 PM · physicsplayerglitching

player glitching through floor when turning

so i found that my player goes forward okay but when i try and turn he starts to glitch and then eventually falls through the terrain i have tried re-importing the camera and disabling the components on the player one by one but it didn't seem to help here is a video of whats happening https://streamable.com/jfn63

here is all my code please tell me if you require more info

player.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class Player : MonoBehaviour {
 
     public Slider HealthBar;
 
     public float CurrentHealth { get; set; }
     public float MaxHealth { get; set; }
 
     public float Speed = 6.0f;
     public float jumpSpeed = 8.0f;
     public float rotateSpeed = 5.0f;
 
     float gravity = 9.8f;
     Vector3 moveDirection = Vector3.zero;
 
     Animator anim;
     CharacterController cc;
 
     static int idleState = Animator.StringToHash("Base Layer.Idle");
     static int moveState = Animator.StringToHash("Base Layer.Walk");
 
     AnimatorStateInfo currentBaseState;
 
     
 
     // Use this for initialization
     void Start () {
 
         MaxHealth = 20f;
         //resets players health on load
         CurrentHealth = MaxHealth;
 
         HealthBar.value = CalculateHealth();
 
         anim = GetComponent<Animator>();
 
         cc = GetComponent<CharacterController>();
 
         if (!anim)
         {
             Debug.Log("No Animator Found.");
         }
 
         if (!cc)
         {
             Debug.Log("No CharacterController Found.");
         }
     }
     
     // Update is called once per frame
     void Update () {
 
 
         anim.speed = Speed;
         //Debug.Log(tag);
         //Debug.Log(Speed);
 
         if (cc.isGrounded)
         {
             float moveForward = Input.GetAxis("Vertical");
 
             moveDirection = new Vector3(0, 0, moveForward);
 
             transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
 
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= Speed;
 
             if (Input.GetButton("Jump")) 
             {
                 moveDirection.y = jumpSpeed;
 
                 anim.SetTrigger("Jump");
             }
             anim.SetFloat("Speed", moveForward);
         }
 
         moveDirection.y -= gravity * Time.deltaTime;
 
         cc.Move(moveDirection * Time.deltaTime);
 
         currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
 
         //if (currentBaseState.fullPathHash == moveState)
         //{
         //    if (Input.GetButtonDown("Fire1"))
         //    {
         //        anim.SetTrigger("Punch");
         //    }
         //}
 
         //if (currentBaseState.fullPathHash == idleState)
         //{
         //    if (Input.GetButtonDown("Fire1"))
         //    {
         //        anim.SetTrigger("Punch");
 
         //        // Instantiate Something
 
         //    }
         //}
 
        
 
         if (Input.GetButtonDown("Jump"))
         {
             anim.SetTrigger("Jump");
         }
 
         while(Input.GetKeyDown(KeyCode.LeftShift))
         {
             Speed = 10;
         }
 
         if (Input.GetKeyDown(KeyCode.E))
         {
             anim.SetTrigger("Dead");
         }
 
         
     }
 
     void OnCollisionEnter(Collision collision)
     {
         
 
         Debug.Log(name);
 
         if (collision.gameObject.name == "Finish")
         {
             Debug.Log("you finished the game");
 
             SceneManager.LoadScene(1, LoadSceneMode.Additive);
         }
 
         if(collision.gameObject.name == "Lava")
         {
             Speed = 5;
             DealDamage(2);
         }
 
         while (collision.gameObject.tag == "Ice")
         {
             Speed = 20;
         }
 
         while (collision.gameObject.tag == "Water")
         {
             Speed = 2;
         }
     }
 
     void DealDamage(float DamageValue)
     {
         CurrentHealth -= DamageValue;
         HealthBar.value = CalculateHealth();
 
         if(CurrentHealth == 0)
         {
             Die();
         }
     }
 
     float CalculateHealth()
     {
         return CurrentHealth / MaxHealth;
     }
 
     void Die()
     {
         CurrentHealth = 0;
         anim.SetTrigger("Dead");
 
     }
 }
 


GameManager.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 public class GameManager : MonoBehaviour {
 
     static GameManager _instance;
 
     // Use this for initialization
     void Start () {
 
         if (instance)
             DestroyImmediate(gameObject);
         else
         {
             DontDestroyOnLoad(gameObject);
             instance = this;
         }
 
         //SceneManager.LoadScene(0, LoadSceneMode.Additive);
 
     }
 
     public static GameManager instance
     {
         get { return _instance; }
         set { _instance = value; }
     }
 
     
     
 
     // Update is called once per frame
     void Update () {
        
 
         
     }
 
     public void StartGame()
     {
         SceneManager.LoadScene("main");
     }
 
     public void Quit()
     {
         Application.Quit();
         Debug.Log("This is where i Would Quit");
     }
 
     public void LoadNewScene(string Scene)
     {
         SceneManager.LoadScene(Scene);
     }
 
     public void MainMenu()
     {
         SceneManager.LoadScene(0);
     }
 }
 


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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cornelis-de-Jager · Nov 19, 2018 at 09:08 PM

I would disable gravity when touching the ground. =

 if (cc.isGrounded)
          {
             // Do things
          } else {
            // Move it move downward
             moveDirection.y -= gravity * 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 Kyle_Nichol · Nov 19, 2018 at 09:13 PM 0
Share

i added the else statement and it still seems to have the same problem

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

235 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 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 do I make a surface move a player forward? 1 Answer

I'm having issues with collision and Physics 1 Answer

Player moves indefinitely after collision 0 Answers

How to make my player move forward when on an object 1 Answer

How can you make a level fly in and fall out as the player progresses? 0 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