x


RTS movement with walking animation.

Hi there!

The only animated 3D character I could get to try this engine out is the Hero from Locomotion System,... so I created a terrain, and I wrote the following script to move it around the map with the "click to move", rts-like movement.

var smooth:int; // Determines how quickly object moves towards position

private var targetPosition:Vector3; function Start () { targetPosition = transform.position; }

function Update () { var playerPlane = new Plane(Vector3.up, transform.position); var rayo = Camera.main.ScreenPointToRay (Input.mousePosition); var puntochoque = 0.0;

if(Input.GetKeyDown(KeyCode.Mouse0))
{        
    if (playerPlane.Raycast (rayo, puntochoque)) {
        var targetPoint = rayo.GetPoint(puntochoque);
        targetPosition = rayo.GetPoint(puntochoque);
        var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
        transform.rotation = targetRotation;
    }   
}

smooth = 5.0;
transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);

}

But now I'd like to add the animation of "RunForward" (incorporated in the model) in this code in order to get the walking animation while the character is moving. Maybe the way I use to move the character isn't the proper one...

So, how could I add the animation?

Thanks in advance!

more ▼

asked Aug 10 '11 at 01:40 AM

Felipaoo gravatar image

Felipaoo
1 1 1 1

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

2 answers: sort voted first

Do you still need help with this? in case you do:

if you want to play an animation, all you have to do is

Animation theWalkAnimation; //This is the name of the animation, it doesnt have to         //                                    be the same as the actual name of the animation that //                                    is on the character.

function Start()
{
    theWalkAnimation = GetComponent<Animation>(); //This gets the animation component of the gameobject the script is attached to.
}

function Update()
{
     theWalkAnimation.Play();
}

by the looks of it you're using javascript, but this should work in both java and C#.

more ▼

answered Apr 25 '12 at 05:16 AM

IronFurball gravatar image

IronFurball
168 2 4 5

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

ONLINE STORE :

====( http://www.etradinglife.com )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,****, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

Christan Audigier bikini $23

Ed Hardy Bikini $23

Smful short_t-shirt_woman $15

ed hardy short_tank_woman $16

Sandal $32

christian louboutin $80

Sunglass $15

COACH_Necklace $27

handbag $33

AF tank woman $17

puma slipper woman $30

====( http://www.etradinglife.com )=====

more ▼

answered Aug 10 '11 at 02:02 AM

xcgbnjtrhrt gravatar image

xcgbnjtrhrt
0

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

x3807
x1374
x500
x156
x104

asked: Aug 10 '11 at 01:40 AM

Seen: 1022 times

Last Updated: Apr 25 '12 at 05:16 AM