Game Development Community

Question about using behaviors?

by Firas · in Torque Game Builder · 04/02/2007 (12:57 am) · 1 replies

Behavior is really greate addition to the TGB so I wont to thank TGB team for there greate work.

my question:
the behavior is nice but still cloudy for me, the scenario I'm trying to implement in behaviors is:

I have Object1 and Object2, if I click the left mouse button then Object1 thru a ball on Object2, so Object2 run specific animation (not explosion).

How can I implement this scenario using behaviors?

thanks in advance.

#1
04/02/2007 (9:09 am)
As with most things, there are several ways you could go about this. The way I would do it:

Create two behaviors - MouseDownLaunch and PlayAnimationOnCollision

Give MouseDownLaunch an 'object' field type called 'target', and an 'object' field type called 'ball'. Then, in the onMouseDown callback, clone the ball (%this.ball.cloneWithBehaviors()), and set it's velocity to the direction of the target. If you don't know how to do that, check out the FollowMouseEx behavior in the BehaviorPlayground project (games/BehaviorPlayground/game/behaviors/input).

Then, in PlayAnimationOnCollision, call %this.owner.stopAnimation in the onAddToScene callback and %this.owner.playAnimation in the onCollision callback.

You'll have to set up all the collision info in the editor just like normal. So, enable sendCollision on the ball, receiveCollision on the target, and collisionCallback on the target.

I'll be writing up more info on the behavior system, including how to write your own behaviors, later today.