I’m working on a game where the player is constantly running (third person) and has the ability to jump. With my script at the moment, when the player jumps (achieved by an upwards swipe on android in another script), the player stops moving forward and jumps, then returns to moving forward. I want it so that he jumps and continues but everything I try seems to not work. Any ideas? I’ve added some of the code with irrelevant parts removed. I realise it’s not the most elegant code but for the moment I’m just trying to get this working so I can make other progress. Thank you.
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded deadPlayer == false) {
// We are grounded, so recalculate
// move direction directly from axes to keep right direction after turn
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
isMoving = true;
var MoveDirection = transform.forward;
controller.Move(MoveDirection * Time.deltaTime * speed);
// Tilt controls
//direction.x = -Input.acceleration.y * moveSpeed;
direction.x = Input.acceleration.x * moveSpeed;
if (direction.sqrMagnitude > 1)
direction.Normalize();
// Make it move 10 meters per second
direction *= Time.deltaTime;
direction = Camera.main.transform.TransformDirection(direction);
// Move object without transform to take boundaries into consideration
controller.Move (direction * speed);
if (jump == true) {
moveDirection.y = jumpSpeed;
camera1.audio.PlayOneShot(jumpSound);
isJumping = true;
jump = false;
}
else
{
isJumping = false;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}