So, I’ve started on my own character movement script and can’t seem to make my character jump without continuously flying if I continue to hold space down. I’ve looked around online for a solution and found a few jumping tutorials but they’re not making very realistic jumps, can someone help me fix this? Here’s my code so far (I’ve removed all the script I had for jumping)
var rotationSpeed: float = 10;
var walkSpeed : float = 3;
var gravity : float = 50;
private var yRot : float;
function Update ()
{
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var height : Vector3 = transform.TransformDirection(Vector3.up);
if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal"))
{
animation.CrossFade("Default Walk",0.2);
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
}
else
{
animation.CrossFade("Default Idle",0.2);
}
if(Input.GetAxis("Mouse X"))
{
yRot += 10* Input.GetAxis("Mouse X");
}
transform.rotation = Quaternion.Euler(0,yRot,0);
Controller.Move(height * gravity * Time.deltaTime);
}