x


3rd person controller

i understand that many people using the script to control only one animation file which they separated into 3 parts by keyframes.(idle, walk and run)

However i did the three animations in 3 separate files...i do not know how to control these three files together by the script and make the 3rd person controller..

really thanks for the help:D

more ▼

asked Aug 08 '10 at 12:20 PM

nicole gravatar image

nicole
21 14 15 22

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

2 answers: sort voted first

You are partially correct. Although, many people don't use 1 animation file and jump around in it, Unity let's you split that file so that there are actually 3 animation files (idle, walk, run.) Making 3 separate files, I assume you mean using the character@animation method, will give you the same number of animation files as the other method. To control them through scripting, you use the exact same method for both.

function Update () {
    if(Input.GetAxis("Vertical") > .1) {
         if(Input.GetButton("Fire1")) {
              animation.CrossFade("yourRunAnimationName");
         }

         else {
              animation.CrossFade("yourWalkAnimationName");
         }
    }

    else {
         animation.CrossFade("yourIdleAnimationName");
    }
}

P.S. This method is extremely basic, and is just meant to give you an example. You probably want to write your own for your actual script.

more ▼

answered Aug 08 '10 at 12:54 PM

Peter G gravatar image

Peter G
17.3k 22 51 149

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

this is my script.. -i cant switch between the animations by using the xxx@xxx method and it only generate walking cycle..but can only rotate..

private var walkSpeed : float = 1.0; private var gravity = 100.0; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController; //private var power : float = 4.0;

function Start() { charController = GetComponent(CharacterController); animation.wrapMode = wrapMode.Loop; }

function Update () { if(charController.isGrounded == true) { if(Input.GetAxis("Vertical") > .1) {

         animation["walk"].speed = 1;
         animation.CrossFade("walk");
         walkSpeed = 6;


        if(Input.GetButton("run")  )
        {

            animation.CrossFade("run");
            walkSpeed = 10;
        }
        else
        {

            animation["walk"].speed = 1;
            animation.CrossFade("walk");
            walkSpeed = 6;
        }  


    }
    else if(Input.GetAxis("Vertical") < -.1)
    {

        animation["walk"].speed = -1;
        animation.CrossFade("walk");
        walkSpeed = 6;
    }
    else if(Input.GetButton("jump")  )
        {
            animation["jump"].speed = 1;
            animation.CrossFade("jump");
            walkSpeed = 6;
        }
    // Create an animation cycle for when the character is turning on the spot
    if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))
    {
        Debug.Log ("horizontal n not get axis vertical");
        //animation.CrossFade("walk");
    }

    Debug.Log("turning...");


    transform.eulerAngles.y += Input.GetAxis("Horizontal");

    // Calculate the movement direction (forward motion)
    moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
    moveDirection = transform.TransformDirection(moveDirection);

}

moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection * (Time.deltaTime * walkSpeed));

}

this is my movement control script to switch the animations..

function Start() { animation.wrapMode = WrapMode.Loop; }

function FixedUpdate () { if(Input.GetAxis("Vertical") > .1) {

        if(Input.GetButton("run")  )
        {

            animation.CrossFade("run");
            walkSpeed = 4;
        }
        else
        {

            animation["walk"].speed = 1;
            animation.CrossFade("walk");
            walkSpeed = 1;
        }  


    }
    else if(Input.GetAxis("Vertical") < -.1)
    {

        animation["walk"].speed = -1;
        animation.CrossFade("walk");
        walkSpeed = 1;
    }
    else if(Input.GetButton("jump")  )
    {
            animation["jump"].speed = 1;
            animation.CrossFade("jump");
            walkSpeed = 4;
    }
    // Create an animation cycle for when the character is turning on the spot

}

more ▼

answered Aug 11 '10 at 02:04 AM

nicole gravatar image

nicole
21 14 15 22

(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:

x32

asked: Aug 08 '10 at 12:20 PM

Seen: 3032 times

Last Updated: Aug 08 '10 at 12:20 PM