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 pokerface0958 · Jan 21, 2021 at 08:53 PM · movementcharactercontrollergravity

When my player climb something, after a certain point it start to float

I followed a tutorial and made a third person movement using character controller, but for some reason whenever I climb to a specific point, I always start floating and my gravity script doesnt work either. This is my code :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Movement : MonoBehaviour
 {
     public CharacterController Controller;
     public Transform Camera;
     public Animator Animator;
 
     public float Speed = 6f;
     public float TurnSmoothTime = 0.1f;
     float TurnSmoothVelocity;
 
     Vector3 Velocity;
     public float Gravity = -19.62f;
 
     public Transform GroundCheck;
     public float GroundDistance = 0.4f;
     public LayerMask GroundMask;
     public bool IsGrounded;
     
    
     void Update()
     {
         IsGrounded = Physics.CheckSphere(GroundCheck.position, GroundDistance, GroundMask);
 
         if (IsGrounded && Velocity.y < 0)
         {
             Velocity.y = -2f;
         }
 
         float Horizontal = Input.GetAxisRaw("Horizontal");
         float Vertical = Input.GetAxisRaw("Vertical");
         Vector3 Direction = new Vector3(Horizontal, 0f, Vertical).normalized;
 
         bool IsMoving = false;
         bool IsRunning = false;
 
         
 
         if (Direction.magnitude >= 0.1f)
         {
             IsMoving = true;
             float TargetAngle = Mathf.Atan2(Direction.x, Direction.z) * Mathf.Rad2Deg + Camera.eulerAngles.y;
             float Angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, TargetAngle, ref TurnSmoothVelocity, TurnSmoothTime);
             transform.rotation = Quaternion.Euler(0f, Angle, 0f);
 
             Vector3 MoveDirection = Quaternion.Euler(0f, TargetAngle, 0f) * Vector3.forward;
             Controller.Move(MoveDirection.normalized * Speed * Time.deltaTime);
 
             if (Input.GetKey(KeyCode.LeftShift))
             {
                 IsRunning = true;
                 Speed = 10f;
             }
         }
 
         if(Input.GetKeyDown(KeyCode.Space) && IsGrounded)
         {
             Velocity.y = Mathf.Sqrt(3f * -2f * Gravity);
         }
 
         // Gravity
         Velocity.y += Gravity * Time.deltaTime;
         Controller.Move(Velocity * Time.deltaTime);
 
         Animator.SetBool("Moving", IsMoving);
         Animator.SetBool("Running", IsRunning);
     }
 }

Any help is appreciated.

Comment
Add comment · Show 4
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 zolteeeen · Jan 21, 2021 at 11:21 PM 1
Share

$$anonymous$$aybe use Rigidbody and then you could use something like AddForce / AddConstantForce for gravity

avatar image pokerface0958 zolteeeen · Jan 22, 2021 at 05:52 PM 0
Share

i hoped to use a character controller to add some extra functions along the line. managed to fix the issue as well. thanks tho :)

avatar image logicandchaos · Jan 22, 2021 at 03:00 PM 1
Share

Can you post a video? And maybe your insector

avatar image pokerface0958 logicandchaos · Jan 22, 2021 at 05:51 PM 0
Share

managed to solve the issue. turns out the collider i used for a 3d object was causing it. this was fixed when i changed it to a mesh collider.

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

183 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

Related Questions

Character Controller / Charactor Motor has no inputs? 1 Answer

Movement with character controller on different walls 0 Answers

Round Planets and Movement on them 2 Answers

Charactercontroller won't go down, only goes up 0 Answers

How to change the angle my character falls at 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