Hi all im having a bit of a problem making my character jump. Its just a cude that im using for a prototype 2.5D platformer.
Ive spent the past hour looking on google but i can find anything that will help.
Ive gotten the object to jump up but it keeps getting faster every time you press the ‘space’ bar and it wont come back down :neutral:
Heres all of my code for the player:
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour
{
public float speed;
public float jump = 10.0f;
public float gravity = 10.0f;
// Start
//-----------------------------------------------------------------------------------
// Use this for initialization
void Start ()
{
}
// Update
//-----------------------------------------------------------------------------------
// Update is called once per frame
void Update ()
{
Movement();
}
// Movement
//-----------------------------------------------------------------------------------
void Movement()
{
if (Input.GetKey(KeyCode.W)) // Up
{
float moveVertical = Input.GetAxis("Vertical") * speed * Time.deltaTime * 5;
transform.Translate(Vector3.up * moveVertical);
}
if (Input.GetKey(KeyCode.S)) // Down
{
float moveVertical = Input.GetAxis("Vertical") * speed * Time.deltaTime * 5;
transform.Translate(Vector3.up * moveVertical);
}
if (Input.GetKey(KeyCode.D)) // Left
{
float moveHorizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime * 5;
transform.Translate(Vector3.left * moveHorizontal);
}
if (Input.GetKey(KeyCode.A)) // Right
{
float moveHorizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime * 5;
transform.Translate(Vector3.left * moveHorizontal);
}
if (Input.GetKeyDown(KeyCode.Space)) // Jump
{
rigidbody.AddForce(Vector3.up * jump);
}
}
}
I hope someone can help me as soon as possible.
Thanks