Smoothly move with Character Controller

Hi

I am trying to make a player controller script using the built in Character Controller and I need the player to smoothly move. Right now the player movement is very stiff. It instantly gets the speed I’ve set it to and instantly stops. I tried to pull some code from another rigidbody player I made before to smooth the movement but no luck. I have been searching all over the web and still no luck. So this is my last resort. I know this question have been asked tons of times but I can’t find anything that really works for me.

Here’s my current code at a attempt to smooth the movement.

cc = CharacterController.
moveDirection = Vector3.
-----
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= movementSpeed;
Vector3 targetMoveAmount = moveDirection * movementSpeed;
moveDirection = Vector3.SmoothDamp(moveDirection, targetMoveAmount, ref smoothMoveVelocity, .15f);
                
if (Input.GetKeyDown(movementSettings.jumpKey))
{
    if (movementSettings.enableJumping && cc.isGrounded)
    {
        moveDirection.y = movementSettings.jumpForce;
    }
}

moveDirection.y -= movementSettings.gravity * Time.deltaTime;
cc.Move(moveDirection * Time.deltaTime);

As I said before, this code moves the player but does not move it smoothly.

Any help is appreciated!

Also, if you have some extra time, I also need some help with the jumping. Right now if I try and jump is moves me back to the ground really fast. I followed the Unity docs for that so I have no idea why it would do that.

You can try using Input.GetAxis instead of Input.GetAxisRaw that will make movement smoother since I think GetAxisRaw just checks if input’s either on or off, whereas GetAxis transitions from off to on. You can also have a look at Mathf.lerp . You can use that to transition from one value to another smoothly. Just in the example on the code reference they use Time.time for the transition time where you probably want to use Time.deltaTime.

Hopefully that helps somewhat.

It really is simple. Add a rigidbody to the camera. Then use the addforce method. My code is short, and very effective.

using UnityEngine;
using System.Collections;

public class moveEnact : MonoBehaviour 

{
	public float mvar = 2000;
	 void Start()

	{
		Debug.Log ("success ME");
		GetComponent<Rigidbody>().AddForce (transform.forward * mvar);
	}

I just used void start for an example

@RealMTG Hi,

I’m having some issues getting this smooth movement to work on my code too. The suggestions above don’t make sense to me. Would you be willing to chat really quick and help me with this since it seems you have figured it out?

Thanks,
Andrei