x


Trigger animation problem

I have a script here, to trigger an animation via collider. It DID work very well, i tried it at work in our project. Thing is, i'm doing a personal project. And i tried to use the same script on my character, but it doesn't work. It give me the feedback so the script does something. Only thing is, my characters animation doesn't work. Should i post the script here? Or do guyz need some more information first?

* sorry for the mess up!! here is the script*

var target: Transform;

function Start (){
    if (target == null && GameObject.FindWithTag("Player"))
    target = GameObject.FindWithTag("Player").transform;
    collider.isTrigger = true;
}


function OnTriggerEnter() {
    if(target.gameObject.tag == "Player" ) {

    target.animation.Play("push");

    collider.isTrigger = true;

    print ( "Touch!");



    }
}


function OnTriggerExit() {
    if(target.gameObject.tag == "Player" ) {

    collider.isTrigger =true;   
    target.animation.Play("idle");
    print ( "Untouch..");

    }
}
more ▼

asked Jul 25 '10 at 12:27 PM

Cyriel gravatar image

Cyriel
33 2 2 5

The more details the better. Assuming that the script is fine I would say your model hasn't been set up correctly or you've missed a step on the script.

Jul 25 '10 at 12:32 PM spinaljack

Well, i now used a trigger via raycast, and it works. Only problem i got now, is that it triggers as soon as the script starts. But when i turn of the trigger before playing, it doesn't trigger.

Jul 25 '10 at 05:35 PM Cyriel

Post your scripts

Jul 25 '10 at 06:20 PM spinaljack

erhm... i'm getting all kinds of weird stuff. The whole thing is script, but i guess the website doesn't see that. you can tell i'm not a coder lol. Sorry for that.

Jul 25 '10 at 09:03 PM Cyriel
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

Try this:

var target: GameObject;

function Start (){
    if (target == null && GameObject.FindWithTag("Player"))
    target = GameObject.FindWithTag("Player");
    collider.isTrigger = true;
}


function OnTriggerEnter(other : Collider) {
    if(other.gameObject.tag == "Player" ) {
       other.gameObject.animation.Play("push");
       print ( "Touch!");
    }
}


function OnTriggerExit(other : Collider) {
    if(other.gameObject.tag == "Player" ) { 
       other.gameObject.animation.Play("idle");
       print ( "Untouch..");
    }
}
more ▼

answered Jul 26 '10 at 12:38 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

Although, given the push animation I'm thinking you want a solid collider with on collision enter instead of trigger so that the player can do his push animation without entering the trigger...

Jul 26 '10 at 12:39 PM spinaljack

Hey,

Sorry for the late reply. I didn't expect an answer anymore. I tried your script but the results are the same. maybe i'm taking the wrong aproach here. But i thought this would be the most simpel.

i still get "touch" and "untouch" but nothing happens, also no errors. I could upload the project if you want?

Jul 30 '10 at 04:30 PM Cyriel
(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:

x3783
x1693
x984

asked: Jul 25 '10 at 12:27 PM

Seen: 1529 times

Last Updated: Jul 25 '10 at 09:19 PM