Hello, i’ve just started scripting in c#, i’ve managed to create a Character movement script, but my jump isn’t really smooth, it just seems like it transports in the air, and falls down with gravity.
How can i make him go smooth? so it goes smoothly up and down?
This is my script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float playerSpeed = 5.0f;
public float jumpheight = 5.0f;
public bool isFalling = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.D)) {
transform.Translate (Vector3.right * playerSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (Vector3.left * playerSpeed * Time.deltaTime);
}
if (Input.GetKeyDown (KeyCode.Space) && isFalling == false) {
isFalling = true;
transform.Translate (Vector3.up * jumpheight * Time.deltaTime);
}
}
void OnCollisionEnter (Collision col)
{
isFalling = false; }
}
Thanks in advance!