Game Development Community

Buttons without animation

by Timothy Volpe · in Torque Game Engine Advanced · 03/12/2010 (8:08 pm) · 5 replies

I've been messing around with shapes, and a made a button model, but I can't seem to get it to do something when I click it, or get it to do what I want correctly. I made it do something when I bump it, but thats not what I'm looking for. What would be the best thing I should use to get it to do something? Everything I try seems to produce a different issue. Its just a model with a simple box collision mesh. If you want to know what the button did, it just killed the player, I started out simple like that, just to get the feel of it and make a button template.

#1
03/13/2010 (5:15 am)
DTS shapes, when loaded with animations, need to be told via scripting 'when' to play the sequence; the engine does not understand when to play the animation....that seems to be the situation from your description.

This is done via several methods....during runtime.

You can directly call an animation on a shape via some stock engine functions... setActionThread() | setArmThread() | playThread(). How these functions interact with various animation 'types' needs to be researched. Read up on the DSQ files and DTS files in the Artist Section of the Documentation.

So, from your description of your animated art asset, you have:

1. a button 'shape' with some animation.
2. when this button activates it's animation, player object dies.

While seemingly simple; actually from your description several steps will need to be taken to get a DTS shape affecting the 'client'.

Firstly, you'll need to establish 'how' you want this DTS shape playing it's animation...with an onCollion(); calling or as a use(); key binding.

From your description, it sounds as though you're using the onCollision(); callback to 'activate' the sequence inside the DTS shape.

That is fine and good and quite a natural point at which to activate the animation, but then you'll have to modify[overwrite] the function, probably via a Namespace calling of the function, to get the button to then pass some instructions along to the obj/client 'colliding' with the button, to then activate that DTS shape to play a named sequence.

So, it sounds as though you have a datablock setup for the art asset, otherwise it wouldn't be appearing in the Mission/Scene...good start.

Now, I would say: modify the onCollision callback to activate the player, something like this:

function Armor::onCollision(%this,%obj,%col,%vec,%speed) 
{
   if (%obj.getState() $= "Dead")
      return;
   echo("Armor::onCollision( " @%this @" , " @ %obj @ " , " @%col @ " , "" @%vec @ "" , " @%speed @ " )");

   // Try and pickup all items
   if (%col.getClassName() $= "Item")
      %obj.pickup(%col);

   // Mount vehicles
   %this = %col.getDataBlock();
   echo("My classname:" @ %obj.getclassname());
   echo("Collided classname:" @ %col.getclassname());
   echo("Can I Mount?:" @ %obj.mountVehicle);
   echo("State: " @ %obj.getState());
   echo("Is it mountable?:" @ %col.mountable);
   if ((%this.className $= WheeledVehicleData) && %obj.mountVehicle &&
         %obj.getState() $= "Move" && %col.mountable) {

      // Only mount drivers for now.
      %node = 0;
      %col.mountObject(%obj,%node);
      %obj.mVehicle = %col;
   }
}
Here is the player onCollision() function; notice how many different things happen when the player collides with 'objects' in the world...you could do the modifying here, or you could setup your 'button' shape with a similar function to isolate this action to only the affect the player when 'colliding' with the button.
Here's some code showing what happens to a 'healthItem'...when collided with:
function HealthPatch::onCollision(%this,%obj,%col)
{
   // Apply health to colliding object if it needs it.
   // Works for all shapebase objects.
   if (%col.getDamageLevel() != 0 && %col.getState() !$= "Dead" ) {
      %col.applyRepair(%this.repairAmount);
      %obj.respawn();
      if (%col.client)
         messageClient(%col.client, 'MsgHealthPatchUsed', '\c2Health Patch Applied');
         serverPlay3D(HealthUseSound,%obj.getTransform());
   }
}

There are a number of ways to set this up...depending upon your final intention. I would suggest to 'sketch' out what you want happening[flowchart perhaps??] happening, then set about scripting it into action...notice what events unfold when the health item is 'collided' with; damage check...etc

I'm sure some far more advanced scriptors will start adding suggestions on how to proceed to the finish you are looking for...shouldn't be too hard from your post.

Good luck!

I believe there is a tutorial on this subject in the documentation or TDN...uses the Torque logo as an object.
#2
03/13/2010 (6:16 am)
...try something like this perhaps...
try something like this:
function myDeathButton::onCollision(%this,%obj,%col)
{
    //sanity check first, why do this if client is in state of death
    if (%col.getDamageLevel() != 0 && %col.getState() !&= "Dead" ) {
       %col.applyDamage(%this.maxDamage); //alive?  not anymore...bye
       %obj.playThread(0,'myCoolDeathSeq');  //oh, btw, see what happens when you touch me? my DTS has this cool animation loaded!
          if (%col.client) // only thing that makes this interesting is it happening to you, the player
             messageClient(%col.client, 'MsgDeathButtonTouched', '\c2You died because you touched a myDeathButton object');
     }
}
#3
03/13/2010 (12:14 pm)
It doesn't look like your understanding my question... I said that I could get the button to complete a task when the player collides with it, but I wanted an idea of what to do on the event that the player clicks it. Unexplained, but by 'click' I mean when the client presses a key (Was going to be X) it would call a function like "activeButton(%button)" %button would be a DTS shape that is in front of the player (the reach has a limit) and I want to know what I should put in the keybind function. Ill try out the things you used and edit them a bit though, thanks.

But, thinking about it, it brings up a small MS3D animation question I had. When I make an animation, and I use the DTS Plus exporter, and I add it to the export list, and click "Export DSQ" what do I do with the files? Do I need the .cs? Do I need teh Crash Dump File? Is the DSQ ready to be used?
#4
03/13/2010 (2:25 pm)
The DSQ is ready to be used after exporting.

You need a .cs file with a TSShapeConstructor datablock to 'load' the DSQ animations into the DTS shape; much like the default 'player' avatar which has a library of about 10 or separate animation files that get loaded into the shape when the script is executed. You don't 'need' the DMP file for any purpose beyond error checking the shape by reading the file.

Depending upon how complex your %button object is with animations, you could probably 'embed'/export the animations inside the DTS already.

Now that your intent is a bit more clear, I think you could leverage the 'use' function to do what I outlined for the 'onCollision' function. You would need to do a keybind to launch the whole cycle, sounds like you want a raycast check for limit of 'use' of the object.


...is this for like opening a door? or something similar, you may need to exactly outline what you are doing to get a more complete answer; I'm more the Artist than Programmer.
#5
03/16/2010 (1:46 pm)
Its like how a lot of games have an "activate" button. Thats what this is like. Its so you can use things without having to be holding "hands" or nothing. You can do this while holding a weapon, and does not launch an animation. It will basicly call something like "ObjectActivate" on what the crosshair is pointed at, and must be in within a reasonable distance of the player, or client, or whatever label you have on it.