x


problems with my making my Character crouch

var speed = 6.0; var jumpSpeed = 8.0; var gravity = 20.0; var run = 10.0; var slow = 3.0; private var moveDirection = Vector3.zero; private var grounded : boolean = false;

function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

    if (Input.GetButton ("shift")) {
       moveDirection *= run; }

    if (Input.GetButton ("Jump")) {
       moveDirection.y = jumpSpeed;

    if (Input.GetButton ("crouch")) {
       moveDirection *= slow; 

           if (Input.GetButtonDown ("crouch")) {
           transform.localScale.y = 0.5; }
           if (Input.GetButtonUp ("crouch")) {
           transform.localScale.y = 1; }

        }
    }
}


// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}

@script RequireComponent(CharacterController)

This is my whole script so far everything is working except when i try to get my character to crouch nothing happens and the speed doesnt decrease like i want it too if you can see the problem please let me know.

more ▼

asked Dec 02 '10 at 03:06 PM

chris gough gravatar image

chris gough
97 5 7 9

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x40

asked: Dec 02 '10 at 03:06 PM

Seen: 724 times

Last Updated: Dec 02 '10 at 03:06 PM