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!