Question by
Maxi06 · Oct 19, 2020 at 09:31 AM ·
3dcharactercontrollerpc
the jump teleports and isent smooth but the gravity is smooth i cant put a Time.deltaTime.,
private CharacterController charC;
private Vector3 moveDirection = Vector3.zero;
private float walkSpeed = 0.02f;
private float runSpeed = 0.04f;
private float gravityForce = 10.0f;
private float JumpHight = 4.0f;
private void Start()
{
charC = GetComponent<CharacterController>();
}
private void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
moveDirection = new Vector3(moveX, moveDirection.y, moveZ);
if (Input.GetKey(KeyCode.LeftShift))
{
moveDirection *= runSpeed;
}
else
{
moveDirection *= walkSpeed;
}
if (charC.isGrounded && Input.GetButtonDown("Jump"))
{
moveDirection.y = JumpHight;
}
moveDirection.y -= gravityForce * Time.deltaTime;
charC.Move(moveDirection);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613013930im_/https://answers.unity.com/themes/thub/images/avi.jpg)