- Home /
Question is off-topic or not relevant
(CharacterController) Jumping from other script
Hello, in my game I'm using a character controller for the player, and I took the movement script from the unity scripting reference and modified it a little bit.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class PlayerMovementScript: MonoBehaviour {
float speed;
Vector3 moveDirection;
CharacterController cc;
public MouseLookScript mouseLookScript;
public PlayerStatsScript playerStatsScript;
void Start () {
cc = GetComponent<CharacterController>();
}
void Update() {
speed = playerStatsScript.speed/2f;
if (cc.isGrounded) {
moveDirection.x = Input.GetAxis("Horizontal");
moveDirection.z = Input.GetAxis("Vertical");
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
}
else {
moveDirection.x = 0f;
moveDirection.z = 0f;
}
cc.Move(new Vector3(moveDirection.x, -9.8f, moveDirection.z) * Time.deltaTime);
}
void LateUpdate () {
transform.eulerAngles = new Vector3(transform.rotation.x, mouseLookScript.currentYRotation, transform.rotation.z);
}
}
The problem is, in my game, there is no jump button, but if the player picks an item, he would be able to perform a single jump, however this jump is telleporting the player 9 units up instead of jumping, if I try to jump using the movement script (changing moveDirection.y) it works, but I need to make the jump from another script.
From the special ability script this is the important line:
cc.Move(Vector3.up * 10f);
So can anyone tell me how to fix this issue? Thanks in advance.
Follow this Question
Related Questions
Directional Jumping (Help) 2 Answers
why does character controller accelerate off ledges? 1 Answer
Help with animation... Please 2 Answers
can anyone help me to smooth the jump? 0 Answers
Player appears to teleport instead of adding force 2 Answers