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 opscopez · Apr 07, 2014 at 01:16 AM · objectcharactercontrollerdrop

Why does my CharacterController Immediately Drop When Falling from an Object?

Hello!

I'm currently building a basic FPS, and I'm coming across a very peculiar problem.

I have found a way to make my player (built with the CharacterController) jump up and down and it works really well and everything, but I seem to come across a problem when I drop down from an object, such as a building. I can jump up and down with no problem from the building, but when I just drop down without jumping, my CharacterController just immediately falls down really fast.

Here's my Controller.cs code (used for moving the player):

 using UnityEngine;
 using System.Collections;
 
 public class Controller : MonoBehaviour {
 
     public float moveSpeed;
     public float mouseSpeed;
     private float lastMouseSpeed;
 
     public Camera playerCamera;
     public CharacterController player;
 
     private float sprintSpeed;
     private float originalMoveSpeed;
     public static bool sprinting = false;
 
     public float jumpHeight;
     public bool jumping = false;
     private float verticalVelocity;
 
     /* Locks the cursor in place and gets the CharacterController for manipulation. */
     void Start() {
         if (player == null) player = GetComponent<CharacterController>();
         sprintSpeed = moveSpeed * 1.8f;
         originalMoveSpeed = moveSpeed;
         lastMouseSpeed = mouseSpeed;
         Screen.lockCursor = true;
     }
 
     /* Enables player and NPC movement. */
     void Update() {
         // The key movements, (forward, backwards, side-to-side, etc).
         float forward = Input.GetAxis("Forward") * moveSpeed;
         float side = Input.GetAxis("Side") * moveSpeed;
 
         // The mouse movements.
         float rotationSide = Input.GetAxis("Mouse X") * mouseSpeed;
         float rotationForward = Input.GetAxis("Mouse Y") * mouseSpeed;
         transform.Rotate(0, rotationSide, 0);
         playerCamera.transform.Rotate(-rotationForward, 0, 0);
 
         if (Input.GetButton("Sprint")) {
             sprinting = true;
             moveSpeed = sprintSpeed;
         } else {
             moveSpeed = originalMoveSpeed;
             sprinting = false;
         }
 
         verticalVelocity += Physics.gravity.y * Time.deltaTime;
 
         if (player.isGrounded && Input.GetButtonDown("Jump")) {
             verticalVelocity = jumpHeight;
             jumping = true;
         } else {
             jumping = false;
         }
 
         Vector3 movement = new Vector3(side, verticalVelocity, forward);
 
         // As long as the game isn't paused, move and whatnot.
         if (EscapeMenu.paused != true) {    
             movement = GetLookout() * movement;
             player.Move(movement * Time.deltaTime);
         }
     }
 
     /* Returns the rotation (the mouse look) for processing. */
     Quaternion GetLookout() {
         return transform.rotation;
     }
 
     /* Returns the lastMouseSpeed. (Used for inventory and escape menu) */
     public float getLastMouseSpeed() {
         return lastMouseSpeed;
     }
 
     /* Sets the mouse speed. (Potential for options) */
     public void setMouseSpeed(float passedMouseSpeed) {
         this.mouseSpeed = passedMouseSpeed;
     }
 }
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
3
Best Answer

Answer by Ed unity · Apr 08, 2014 at 06:30 PM

Every update you are changing the verticalVelocity. So when you do not jump, the verticalVelocity is not reset and thus when you fall, depending on how long it has been since the last time you jumped, the verticalVelocity will be greater with more time or less with less time. Try only changing the verticalVelocity while falling and cap the verticalVelocity at a min/max so you don't constantly pick up speed while falling.

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 opscopez · Apr 08, 2014 at 09:50 PM 0
Share

Okay! Thanks! :)

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

22 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

Related Questions

How to create a object groundCheck for my character 0 Answers

Ignore collision between character controller and a rigid body object 1 Answer

Throw object in android 1 Answer

How to pick / drop object 1 Answer

Can someone help me with the initialize and pick up script, please? 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