x


Character Animation Question (Bear Force One)

We created a script for our main character (Vlad the Bear), and it links keyboard input to animations we have made in Blender. It goes as follows:

var speed = 3.0;
var rotateSpeed = 3.0;

function Update ()

{

    var controller : CharacterController = GetComponent(CharacterController);
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");
    controller.SimpleMove(forward * curSpeed);



    if(Input.GetAxis("Vertical") )
        {
            animation.CrossFade("twolegrun");

        }
    if(curSpeed < 0.0001)
        {
            animation.CrossFade("stillup");
        }
    if(Input.GetAxis("Vertical") && Input.GetAxis("Horizontal"))
        {
            animation.CrossFade("twolegrun");
        }
    if(Input.GetAxis("Jump") && Input.GetAxis("Vertical"))
        {
            animation.CrossFade("twolegattack");
        }
    if(Input.GetAxis("Jump"))
        {
            animation.CrossFade("twolegattack");
        }

}


@script RequireComponent(CharacterController)

Okay, so when we play it, the animations play for the walking around. However the animation for attacking only plays when the spacebar is held. Is there any way to go about the scripting for the attack as to play the animation fully when the spacebar is tapped, and to return to the moving scripting/animations?

Also is there an absolute value code? I would like to make the bear be able to move forward and turn sideways, but not to be able to walk backwards as it looks unnatural with our current aniamtions.

Thank you !

more ▼

asked May 20 '10 at 04:50 PM

Jake Gordon gravatar image

Jake Gordon
1 1 1 1

I have this problem too =/ Hopefully you find a fix for it

May 02 '11 at 05:27 AM Moon
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

First, for the jump you can use

Input.GetButtonDown("Space")

This fires only once when the key is pressed, then will be checked only after the key has been released and pressed again, so it's good for one-time actions.

For the absolute value you can use:

(Mathf.Abs(YourVariable))

Please seperate your questions next time though. Hope it works :)

more ▼

answered Apr 01 '11 at 10:45 PM

zinnfandel gravatar image

zinnfandel
30 11 16 21

(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x5085
x3793
x1370
x1045

asked: May 20 '10 at 04:50 PM

Seen: 1121 times

Last Updated: May 21 '10 at 04:52 AM