Right now I'm trying to create a gliding jump, wherein if a player holds the control button during a jump the character will fall slower. Here is the code, which at the moment is crashing Unity consistently.
var Health = 0;
var walkSpeed : float = 20.0;
var gravity = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
var jumpSpeed = 2;
function Start()
{
charController = GetComponent(CharacterController);
animation.wrapMode = WrapMode.Loop;
}
function Update ()
{
if(charController.isGrounded == true)
{
if(Input.GetAxis("Vertical") > .1)
{
//if(Input.GetButton("Run"))
//{
//animation.CrossFade("run");
// walkSpeed = 20;
// }
// else
//{
//animation["walk"].speed = 1;
//animation.CrossFade("walk");
//walkSpeed = 20;
//}
}
else if(Input.GetAxis("Vertical") < -.1)
{
//animation["walk"].speed = -1;
//animation.CrossFade("walk");
// walkSpeed = 20;
}
else
{
//animation.CrossFade("idle");
}
// Create an animation cycle for when the character is turning on the spot
if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))
{
//animation.CrossFade("walk");
}
transform.eulerAngles.y += Input.GetAxis("Horizontal");
// Calculate the movement direction (forward motion)
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
} //End Jump
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
if (Input.GetButton ("Glide") && charController.isGrounded != true) {
Debug.Log("Glide button Hit");
rigidbody.AddForce (moveDirection.y * 10);
}//End Glide
}
asked
Mar 16 '10 at 11:25 PM
karl_
2.4k
●
41
●
53
●
70
It would be helpful if you could provide a little more details. Is unity crashing or just not compiling? How is the CharacterCotroller defined in your script?
Alright, I've updated the post with the full script.
Unity is crashing as soon as I hit the left control key, which is what is mapped to "glide"