- Home /
Question by
seahorseracing · Dec 21, 2021 at 03:47 PM ·
movement scriptsmooth
how to get smooth character controls?
I have tried searching for this everywhere but couldn't find anything. here's the simplest character controller i could make for this test. I want smooth speed-up and stop.
public class SmoothMovement : MonoBehaviour
{
Vector3 move = Vector3.zero;
public CharacterController player;
void Update()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
move = transform.right * x + transform.forward * z;
player.Move(move.normalized * 10f * Time.deltaTime);
}
}
Comment
Answer by seahorseracing · Dec 21, 2021 at 05:35 PM
nwm figured it out
public class SmoothMovement : MonoBehaviour
{
private Vector3 valueSmoothed;
private Vector3 valueSmoothedVelocity;
public float smoothTime = 0.2f;
Vector3 move = Vector3.zero;
public CharacterController player;
void Update()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 target = new Vector3(x, 0, z).normalized;
valueSmoothed = Vector3.SmoothDamp(valueSmoothed, target, ref valueSmoothedVelocity, smoothTime);
move = transform.right * valueSmoothed.x + transform.forward * valueSmoothed.z;
player.Move(move * 5f * Time.deltaTime);
Debug.Log("target" + target + " smoothed" + valueSmoothed + " move" + move);
}
}
Your answer
Follow this Question
Related Questions
endless runner movement problem 3 Answers
How can I make smooth movement ? 0 Answers
How to make my 2D movement smooth 1 Answer
Why does the camera smoothly follow in one direction but not the other? 0 Answers