Animating kill triggers
by Mark Hanham · in Torque X Platformer Kit · 08/23/2007 (10:45 am) · 8 replies
Just wondering can you animate kill triggers and if so how.eg.moving bolders,or moving spikes.
i luv the kit i just want to get the most out of it thanks .
i luv the kit i just want to get the most out of it thanks .
#2

Here's an example of a kill trigger that can be toggled:
Another way, which would be easier to set up, but might offer less control would be to add a kill trigger to the the spikes or boulder:

I hope this was helpful.
09/04/2007 (4:00 pm)
There are several ways to accomplish stuff like this. One way would be to subclass the kill trigger so it can be toggled. Then you could put a kill trigger above the spikes, for example, and enable the trigger only when the spikes are up (see the shitty mspaint image below).
Here's an example of a kill trigger that can be toggled:
[TorqueXmlSchemaType]
class ToggleKillTriggerComponent : KillTriggerComponent
{
public bool Enabled
{
get { return _enabled; }
set { _enabled = value; }
}
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info)
{
if (_enabled)
base._onEnter(ourObject, theirObject, info);
}
bool _enabled;
}Another way, which would be easier to set up, but might offer less control would be to add a kill trigger to the the spikes or boulder:

I hope this was helpful.
#3
And how would i tell torque to run animation every 20 secs ,and then stop repeating after 5 goes . I am very greatfull for your help thanks.
So much 2 learn .?
09/05/2007 (5:24 am)
Thank u very well explained but do i hav to code the animation of the bolder the only animation were the dragon in the demo moves is the die screen every thing else is animated still on the spot in cycles.And how would i tell torque to run animation every 20 secs ,and then stop repeating after 5 goes . I am very greatfull for your help thanks.
So much 2 learn .?
#4
09/05/2007 (2:15 pm)
The dragon's death animation is in place too. I think you want rigid physics and collision, not animation. Experiment with the Physics and Collision components.
#5
what is this underneath whats it used 4 im lost
[TorqueXmlSchemaType]class ToggleKillTriggerComponent : KillTriggerComponent{ public bool Enabled { get { return _enabled; } set { _enabled = value; } } protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { if (_enabled) base._onEnter(ourObject, theirObject, info); } bool _enabled;}
09/07/2007 (2:21 am)
Ok so put in an invisible material then attach it to a kill trigger underneath then make animation of spikes going up then do i need a new component what now what activates and how do i judge time .what is this underneath whats it used 4 im lost
[TorqueXmlSchemaType]class ToggleKillTriggerComponent : KillTriggerComponent{ public bool Enabled { get { return _enabled; } set { _enabled = value; } } protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { if (_enabled) base._onEnter(ourObject, theirObject, info); } bool _enabled;}
#6
09/08/2007 (7:03 am)
In the first diagram do i hav to mount the animation to an invisable object so when u hit the invisavle square it triggers the animation
#7
u create a move platform conponent then attach a hazard component to it
then do somthing like 30-x then 30x in the movment component dialog
make shore the image is on a lower layer u can use this 4 alot of different objects
its all done in tx
enjoy
10/09/2007 (9:43 am)
I hav worked out a way to create animated spikes that kill that work on cyle but cant rigger themu create a move platform conponent then attach a hazard component to it
then do somthing like 30-x then 30x in the movment component dialog
make shore the image is on a lower layer u can use this 4 alot of different objects
its all done in tx
enjoy
#8
All they do is turn the kill trigger on and off at specified frames of the animation. I based these classes off Thomas Buscaglia example and just added a little bit of code to synchronise the kill component with my spike animation.
The Classes
ToggleKillTriggerComponent
ToggleHazardComponent
Usage
1) Add your spike animation to the stage.
2) add a ToggleHazardComponent or ToggleKillTriggerComponent to the spike animation.
3) Set ToggleOnFrame to the first frame of the animation you want the component to Kill or damage on collision (E.g the frame the spikes first come out of the ground.)
4) Set ToggleOffFrame to the last frame of the animation you want the component to Kill or damage on collision (E.g the frame the spikes disappear into the ground.)
All done.
Conclusion
This is not an ideal solution as the collision is not actual animate however if your spikes are moving up and down at an average speed you will not notes the difference. + it is easy to implement.
I would love any feedback.
Cheers Levi
01/05/2009 (6:46 pm)
I have two classes I use to create animated spike kill components.All they do is turn the kill trigger on and off at specified frames of the animation. I based these classes off Thomas Buscaglia example and just added a little bit of code to synchronise the kill component with my spike animation.
The Classes
ToggleKillTriggerComponent
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.T2D;
namespace GarageGames.Torque.PlatformerFramework
{
/// <summary>
/// A component to be added to a scene object. The trigger will instantly kill Actors that enter the scene object's boundaries.
/// For dealing damage in increments (such as with 'spikes' or similar objects), use a HazardComponent rather than a KillTriggerComponent.
/// </summary>
[TorqueXmlSchemaType]
class ToggleKillTriggerComponent : KillTriggerComponent
{
#region Public properties, operators, constants, and enums
public int ToggleOnFrame
{
get { return _toggleOnFrame; }
set { _toggleOnFrame = value; }
}
public int ToggleOffFrame
{
get { return _toggleOffFrame; }
set { _toggleOffFrame = value; }
}
#endregion
//======================================================
#region Private, protected, internal fields
protected int _toggleOnFrame;
protected int _toggleOffFrame;
#endregion
//======================================================
#region Private, protected, internal methods
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info)
{
T2DAnimatedSprite animFrames = ourObject as T2DAnimatedSprite;
if (animFrames != null)
{
if (animFrames.CurrentFrame >= _toggleOnFrame && animFrames.CurrentFrame <= _toggleOffFrame)
{
base._onEnter(ourObject, theirObject, info);
}
}
}
#endregion
}
}ToggleHazardComponent
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.T2D;
namespace GarageGames.Torque.PlatformerFramework
{
/// <summary>
/// A component to be added to a scene object. The trigger will deal a specific amount of damage to any Actors that
/// enter the scene object's boundaries. For instantly killing Actors, use a KillTriggerComponent, rathr than a
/// HazardComponent.
/// </summary>
[TorqueXmlSchemaType]
public class ToggleHazardComponent : HazardComponent
{
#region Public properties, operators, constants, and enums
public int ToggleOnFrame
{
get { return _toggleOnFrame; }
set { _toggleOnFrame = value; }
}
public int ToggleOffFrame
{
get { return _toggleOffFrame; }
set { _toggleOffFrame = value; }
}
#endregion
//======================================================
#region Private, protected, internal fields
protected int _toggleOnFrame;
protected int _toggleOffFrame;
#endregion
//======================================================
#region Private, protected, internal methods
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info)
{
ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>();
T2DAnimatedSprite animFrames = ourObject as T2DAnimatedSprite;
if (animFrames != null)
{
if (actor == null)
return;
if (animFrames.CurrentFrame >= _toggleOnFrame && animFrames.CurrentFrame <= _toggleOffFrame)
{
if (_confirmDamage(ourObject, theirObject, actor))
actor.TakeDamage(_damage, ourObject);
}
}
}
#endregion
}
}Usage
1) Add your spike animation to the stage.
2) add a ToggleHazardComponent or ToggleKillTriggerComponent to the spike animation.
3) Set ToggleOnFrame to the first frame of the animation you want the component to Kill or damage on collision (E.g the frame the spikes first come out of the ground.)
4) Set ToggleOffFrame to the last frame of the animation you want the component to Kill or damage on collision (E.g the frame the spikes disappear into the ground.)
All done.
Conclusion
This is not an ideal solution as the collision is not actual animate however if your spikes are moving up and down at an average speed you will not notes the difference. + it is easy to implement.
I would love any feedback.
Cheers Levi
Torque Owner Vishal Bhanderi