Pushing objects linking Push animation? [Solved]

Hi all…

Ive been using unity for a bout 2 weeks now and need a little help with…

I have created character with muiltable animations, Ive manged to get him to push rigid bodie objects eg (Crate/box) whilst still using the “walking” animated cycle.

How can make it force another animation such as an push animation cycle on collision with the create?

im sure its a script thing…

craig :?

if you’re careful about how you do it, you can accomplish this with parenting.

// when you want the character to push the box
box.transform.parent = character.transform;

// Animation logic, etc

// move the character
character.transform.Translate(Vector3.whatever);

// when the character is done pushing
box.transform.parent = null;

Hey…

thanks for the reply!!!

kinda getting what you’ve said although im using rigid bodie for the cube and attached this script attached to my character.

[/code]

// this script pushes all rigidbodies that the character touches
var pushPower = 50;

function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;

// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;

// Calculate push direction from move direction,
// we only push objects to the sides never up and down
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.

// Apply the push
body.velocity = pushDir * pushPower;

}

pushing the object works fine… just need to link in the push animated cycle ive created within Maya.

sorry im very new to all this…

Are you saying you need to start an animation on the crate when it is hit by the other object? I’m not sure what the animation is doing, but you can probably use an OnCollisionEnter function on the crate:-

function OnCollisionEnter(coll: Collision) {
     animation.Play("CrateHit");
}

hey andeee

thanks for the reply,

As my character walks into the create i want it to force a different animation eg “push animation”.

heys guys, worked it out all it needed was…

animation.Play(“push”);

i add this script in the wrong place hence thats why it wasnt work doooohhhh

The new script is now…

[/code]

// this script pushes all rigidbodies that the character touches
var pushPower = 50;

function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;

// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;

// Calculate push direction from move direction,
// we only push objects to the sides never up and down
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.

// Apply the push
body.velocity = pushDir * pushPower;

animation.Play(“push”);

}

will upload youtube link soon to show how it works… thanks for all your help guys!!!