Hello, i have this problem, when i try to jump, first the player goes(or teleports) to fast up, then he came back down normally…how to make it jump normally?
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
//auto
//private Animator anim;
private CharacterController controller;
public float speed = 600.0f;
private Vector3 moveDirection = Vector3.zero;
//gravity
public float gravity = 20.0f;
//jump continuously
public float jumpForce = 30f;
void Start()
{
controller = GetComponent<CharacterController>();
//anim = gameObject.GetComponentInChildren<Animator>();
}
void Update()
{
//if (Input.GetKey("w"))
//{
// anim.SetInteger("AnimationPar", 1);
//}
//else
//{
// anim.SetInteger("AnimationPar", 0);
//}
if (controller.isGrounded)
{
moveDirection = transform.right * Input.GetAxis("Horizontal") * speed;
}
transform.Rotate(0, moveDirection.z * speed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
if (Input.GetKeyDown("space"))
{
transform.Translate(Vector3.up * jumpForce * Time.deltaTime, Space.World);
}
}
}
