Hello, I am here to seek how I would go about achieving this goal, I have researched around looking for how this is done and seen rigid body's but I've never used them, so if possible can someone explain how I cna adapt my following code to do this. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float defaultmoveSpeed = 8.00f; public float moveSpeed = 8.00f; public float jumpSpeed = 15.00f; public float gravity = 20.0f; public float sprintSpeed = 16.00f; private Vector3 moveDirection = Vector3.zero; private CharacterController playerController; // Use this for initialization void Start () { playerController = GetComponent<CharacterController>(); } // Update is called once per frame void Update () { //Movement Section playerMovement(); //methods to which should only be used when player is grounded if (playerController.isGrounded) { jumpMethod(); } } public void jumpMethod() { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= moveSpeed; if (Input.GetButtonDown("Jump")) moveDirection.y = jumpSpeed; } public void playerMovement() { moveDirection.y -= gravity * Time.deltaTime; playerController.Move(moveDirection * Time.deltaTime); if (Input.GetKey("w")) { transform.Translate((Vector3.forward) * moveSpeed * Time.deltaTime); } if (Input.GetKey("S")) { transform.Translate((Vector3.back) * moveSpeed * Time.deltaTime); } if (Input.GetKey("A")) { transform.Translate((Vector3.left) * moveSpeed * Time.deltaTime); } if (Input.GetKey("D")) { transform.Translate((Vector3.right) * moveSpeed * Time.deltaTime); } // Sprint key function if (Input.GetKey("left shift") && Input.GetKey("w")) { moveSpeed = sprintSpeed; } else { moveSpeed = defaultmoveSpeed; } } }
The Goal I want to achieve just so everyone knows is the ability for the user to keep momentum when in air, so if they sprint they'll still be moving that direction when i nthe air.