Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 girlinorbit · Nov 05, 2019 at 09:54 PM · scripting problemmovementmovement script

Player Sliding without any Input

I have a player movement script that tracks if a user is mounted on an object, and if isn't, then the player can move. After all input has stopped, the player continues to slide. I've done quite a bit of research and can't seem to find anything that works:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Networking;
 using UnityEngine.SceneManagement;
 using UMA.CharacterSystem;
 
 public class UnmountedController : MonoBehaviour
 {
     public Animator anim;
     public bool isRunning = false;
     LoginUser Login;
     MountHorse MountHorseScript;
     public bool isMounted = false;
     public bool isMoving;
 
     void Update()
     {
 
             MountHorseScript = GameObject.Find("ScriptManager").GetComponent<MountHorse>();
             isMounted = MountHorseScript.Mounted;
 
         if(!isMounted){
             float vertical = Input.GetAxis("Vertical");
             float horizontal = Input.GetAxis("Horizontal");
             
             
                 transform.Rotate(0, Input.GetAxis("Horizontal") * 2, 0);
             if(Input.GetKeyDown(KeyCode.RightShift) || Input.GetKeyDown(KeyCode.LeftShift)){
                 if(isRunning){
                     isRunning = false;
                 }else{
                     isRunning = true;
                 }
             }
 
             bool hasHorizontalInput = !Mathf.Approximately(horizontal, 0f);
             bool hasVerticalInput = !Mathf.Approximately(vertical, 0f);
             isMoving = hasVerticalInput;
             if(isMoving == true){
                 if(isRunning){
                     transform.position += transform.forward * 6 * vertical * Time.deltaTime;
                 }else{
                     transform.position += transform.forward * 2 * vertical * Time.deltaTime;
                 }
             }
             
             anim.SetBool("Moving", isMoving);
             anim.SetBool("Running", isRunning);
         }else{}
         
             anim.SetBool("Mounted", isMounted);
         
     }
 }
 

Thanks in advance!

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 Magso · Nov 06, 2019 at 08:05 PM 0
Share

Is the constant sliding direction local to the player? If so there's something causing an offset to happen. Are there any other scripts referencing the player?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GrayLightGames · Nov 06, 2019 at 07:17 AM

Hi @girlinorbit, it looks like the position should stop changing once your vertical input is 0. Have you verified that with all input stopped the vertical input is 0? You can use Debug.Log statements to see all the values involved with the logic in your code when you see unintended behavior like this. Just add the following line in your code right before the isMoving == true check (which can simplify just to if (isMoving) and check the console when you are "continuing to slide":

 Debug.Log("Vertical: " + vertical + " hasVertical: " + hasVertical + " isMoving: " + isMoving);

Then you can see if some of your bools or the vertical float value is not what you expect.

Also:

              if(isRunning){
                  isRunning = false;
              }else{
                  isRunning = true;
              }

simplifies to:

 isRunning = !isRunning;

Let us know what you find out!

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
avatar image
0

Answer by girlinorbit · Nov 06, 2019 at 07:49 PM

When I log the input, after the player stops walking, I get this:

 Vertical: 0 hasVertical: False isMoving: False

and the player still slides.

I have tried messing with the rigidbody constraints and that hasn't helped either.

Comment
Add comment · Show 4 · 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 GrayLightGames · Nov 06, 2019 at 08:36 PM 0
Share

Ah didn't realize you have a RigidBody on the player... I don't have as much experience with those, but try disabling the RigidBody component in the inspector during the motion to see if it continues. Is your RigidBody.velocity non-zero? Try forcing that to zero when the input is zero and see if it stops.

Have you tried adding friction by adjusting the mass of the RigidBody? Someone with more experience could weigh in, but I'm sure you could also find a good tutorial on implementing friction with a RigidBody in the meantime.

avatar image Magso GrayLightGames · Nov 06, 2019 at 09:40 PM 0
Share

This could happen if the physics material friction combine is set to $$anonymous$$imum with fiction at a low value or/and gravity has been set really high. Also $$anonymous$$ penetration for penalty may be set to high as well. The default settings of the rigidbody component shouldn't have any of these issues which is why I wondered if the sliding was local to the player or not.

avatar image petur · Nov 06, 2019 at 08:46 PM 0
Share

Is your rigidbody kinematic?

avatar image girlinorbit · Nov 06, 2019 at 09:44 PM 0
Share

I tried removing the RigidBody but lost gravity. I did have a Physic $$anonymous$$aterial connected to my collider. I have been using U$$anonymous$$A, and didn't realize that it was there. Altering the mass of the rigidbody did help some, but after discovering the material I reset the component. Thank you all for your help! You've been amazing!

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

250 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 avatar image avatar image avatar image 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

Slime script? 1 Answer

New to Unity & Scripting, How Do I Create a Movement System Thats About Building Up Speed? 0 Answers

How to I put a speed limit on my character's movement? 1 Answer

My player's movement is slippery 1 Answer

Getting Unusual Input into Animator Controller Script 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