Game Development Community

Really simply question about playing animation on collision

by Orion the Hunter · in Torque Game Builder · 07/26/2013 (9:16 am) · 2 replies

Hi, I apologize for posting while I have another issue open, but this one is fairly small.

I'm trying to make it so when you hit an object, it plays an animation. Here's what I have:
if (!isObject(TuftPickupBehavior))
{
    %template = new BehaviorTemplate(TuftBehavior);
   
    %template.friendlyName = "Tuft of Grass Behavior";
    %template.behaviorType = "Enviroment";
    %template.description  = "Makes the tuft of grass blow when the player runs through it.";

}

function TuftBehavior::onAddToScene(%this, %scengraph)
{
%this.Owner.CollisionActiveRecieve = "1";
%this.Owner.CollisionActiveSend = "1";
%this.Owner.CollisionCallback = "1";
%this.Owner.Immovable = "1";
%this.Owner.setCollidesWith( "ActorObject" );
}

function TuftBehavior::onCollision( %this, %theirObject )
{
echo(%this.Owner @ " has been collided with!");
    if(%theirObject.FlipX)
    {
    %this.owner.flipX = 0;
    }
    else
    {
    %this.owner.flipX = 1;
    }
    
    %this.Owner.playAnimation(TuftAnimation);
}

However, my console is giving me this error:
Quote:game/behaviors/TuftBehavior.cs (32): Unknown command playAnimation.
Object (2792) t2dStaticSprite -> t2dSceneObject -> BehaviorComponent -> DynamicConsoleMethodComponent -> SimComponent -> SimObject
The problem is with the fact that it won't play the animation. it's weird because I can use that function outside of a script (in the console) and it works just fine, and %this.Owner is being recognized and everything... do you know what the problem is?

~ Orion

#1
07/27/2013 (6:51 am)
From the error it looks like your trying to pass it a t2dStaticSprite. You need to declare it as a t2dAnimatedSprite instead :) Hopefully that's just it.
#2
07/27/2013 (8:53 am)
OH! How could I miss that? Thanks, mate! That fixed the problem!

Cheers!