Hey guys.
I have a problem with this. When im just walking my “hero” jumping normal so Code for this is looking like this:
if (Input.GetButtonDown ("Jump")){
moveDirection.y = 7.0;
}
This working fine but… when my character is running then i see veeery big glitch. I know what problem it is but i dont know how can i reaper it. Can you help me?
Code is here.
Screen.lockCursor = true;
var speed : float = 6.0;
var runningSpeed : float = 10.0;
//var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotateSpeed : float = 10.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Mouse X") * rotateSpeed, 0);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButtonDown ("Jump")){
(Input.GetButtonDown ("Run")){ // <---- I wanna check it if my char is running or no. This is not working...
moveDirection.y = 7.0;
}
}
}
if (Input.GetButton ("Run")){ // <-------- Here i have my running "code". Working good but when i jumping then my char is flying somewhere, maybe he have enough of me.
moveDirection *=runningSpeed;
if (Input.GetButtonDown ("Jump"))
moveDirection.y = 10.0;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Help me guys.