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 crazytaco62 · Aug 21, 2018 at 04:51 AM · 3dfirst person controllerfirst person

Player Accelerates When Walking Off Platform

So, I've had a ton of problems in Unity, but I've managed to fix them all. The last one I'm faced with goes as follows:

When I jump/ walk off a platform, my player accelerates about twice as much as he should.

I really don't understand this problem and have spent the past 6 hours trying to fix it, any help is greatly appreciated.

Here's a video: https://www.youtube.com/watch?v=bOkkQD4GQ38

Here's what my code looks like:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMove : MonoBehaviour {
 
     public CharacterController charController;
     public Camera cam;
 
     private int walkSpeed = 3;
 
     [SerializeField] private float jumpMultiplier;
     [SerializeField] private KeyCode jumpKey;
 
     private bool isJumping;
 
     void Awake() {
 
         charController = GetComponent<CharacterController>();
 
     }
 
     void Update() {
 
         MovePlayer();
         jumpInput();
 
     }
 
     private void MovePlayer() {
 
         float horiz = Input.GetAxis("Horizontal");
         float vert = Input.GetAxis("Vertical");
 
         if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W)) {
 
             walkSpeed = 7;
 
         } else {
 
             walkSpeed = 3;
 
         }
 
         Vector3 moveDirSide = transform.right * horiz * walkSpeed;
         Vector3 moveDirForward = transform.forward * vert * walkSpeed;
 
         charController.SimpleMove(moveDirSide);
         charController.SimpleMove(moveDirForward);
 
         
 
     }
 
     private void jumpInput() {
 
         if (Input.GetKeyDown(jumpKey) && !isJumping) {
 
             isJumping = true;
             StartCoroutine(JumpEvent());
 
         }
 
     }
 
     private IEnumerator JumpEvent() {
 
         float vert = Input.GetAxis("Vertical");
 
         Vector3 moveDirForward = transform.forward * vert * (walkSpeed / 2);
 
         charController.SimpleMove(moveDirForward);
 
         charController.slopeLimit = 90f;
 
         do {
 
             charController.Move(Vector3.up * 10 * Time.deltaTime);
 
             yield return null;
 
         } while (!charController.isGrounded && charController.collisionFlags != CollisionFlags.Above);
 
         charController.slopeLimit = 45f;
         isJumping = false;
 
     }
 
 }
 
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 Pseu · Aug 21, 2018 at 05:05 AM

 Vector3 moveDirForward = transform.forward * vert * (walkSpeed / 2);

Transform.forward is in front of the object, not above it. You are also calling the same line:

  charControlller.SimpleMove(moveDirForward);

twice. Once from the MovePlayer() function and once in the enumeration with slightly different values. I suspect you don't want the enumeration one unless you want the player to be forced forward when jumping? If that's the case you might want to put a if (!jumping) before your simple move in MovePlayer().

Also while the enumeration is going on this line:

 charController.Move(Vector3.up * 10 * Time.deltaTime);

Is getting repeatedly called and I suspect stacking on top of each other causing the acceleration.

If none of the above is right and I've read your code horribly wrong then I suggest looking into the settings you have for the Rigidbody on your character as that can alter the way objects fall thus might be causing the acceleration bug. Try lowing your mass or turning off gravity and adding it in via code.

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 crazytaco62 · Aug 22, 2018 at 01:24 AM 0
Share

Tried everything including lowering mass, removing gravity, and your solutions:

Solution results:

1 Not really sure what your idea for a solution on this is

2 removed the ability to move on what ever one I removed (if i removed movedirforward, it didnt let me move forward or backward)

3 It needs to be called several times, just disables jump without it

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

105 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

Related Questions

Code for FP 2 Answers

How do I make a crosshair? 2 Answers

Problem With First Person View Controller 1 Answer

Standard FPS Controller - Smoothing Movement 2 Answers

FPS Controller Confusion... 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