I am trying to get my character to jump in mid air either left right or just straight up depending on which key I am pressing and also need it to ignore my current velocity however I have not been able to achieve this. I have tried everything from making a doublejump function with else if statements to consulting ancient gypsy fortune tellers but have not been able to get my desired result. Heres my script:
var speed : float = 4.0;
var jump : float = 10.0;
var dJump : float = 10.0;
var gravity : float = 20.0;
var dJumpV : float = -4.0;
var dJumpV0 : float = 4.0;
private var canDJump : boolean = false;
private var velocity : Vector3 = Vector3.zero;
var controller : CharacterController;
function Update()
{
if (!controller.isGrounded && canDJump && Input.GetKey("a")
``|| !controller.isGrounded && canDJump && Input.GetKey(“left”))
{
ldJump();
}
if (!controller.isGrounded && canDJump && Input.GetKey("d")
``|| !controller.isGrounded && canDJump && Input.GetKey(“right”))
{
rdJump();
}
if (!controller.isGrounded && canDJump && Input.GetButtonDown("Jump"))
{
velocity.y = dJump;
canDJump = false;
}
if (controller.isGrounded)
{
velocity = Vector3 (Input.GetAxisRaw ("Horizontal"), 0, 0);
velocity = transform.TransformDirection (velocity);
velocity *= speed;
if (Input.GetButtonDown ("Jump"))
{
velocity.y = jump;
canDJump = true;
}
}
velocity.y -= gravity * Time.deltaTime;
controller.Move (velocity * Time.deltaTime);
}
function ldJump()
{
if (Input.GetButtonDown ("Jump"))
{
velocity.y = jump;
velocity.x = dJumpV;
}
}
function rdJump()
{
if (Input.GetButtonDown ("Jump"))
{
velocity.y = jump;
velocity.x = dJumpV0;
}
}