Jump to content

Tweening


LukasPJ

Recommended Posts

Hey guys, I wrote a Tweening class for Torque3D that can be found here.


It's pretty simple to use:

%tween = new Tween(){
   Duration = 5; // This is in seconds.
   Target = SimpleWall; // Any SimObject.
   ValueName = "x"; // Syntactic sugar for the x-coordinate.
   ValueTarget = "5"; // The destination value, this is the absolute value. No relative supported atm.
   EaseDirection = $Ease::Out; // This is just the stock easing values.
   EaseType = $Ease::Circular; // Again, this is a stock thing, I didn't implement the $Ease enum.
};
 
%tween.play();

 

There is syntactic sugar for:

Position (x, y, z).

Rotation(rx, ry, rz).

Scale(sx, sy, sz).


But any numerical field that is accessible through TorqueScript can be used. (Includes globals).


The Tween class has the following methods:

  • Play - Starts the tween
  • Pause - Pauses the tween
  • Rewind - Rewinds the tween back to the beginning (does not stop it currently)
  • Reverse - Plays the tween in reverse

 

And an "onFinished" callback.


The code is not completely finished, but it's fun to play with!

5Yr4O1NU_II

Link to comment
Share on other sites

Tweening? What the hell is tweening!?

There some old TorqueScript for moving stuff around in the old library.cs file that I remember using once.

 

This can do more than just move stuff around! (Also library.cs? What file is that? :P)


For example you could change its scale so it would get wider over time :P Or rotate it in weird ways. It's basically a C++ version of Twillex

Link to comment
Share on other sites

I've been using Twillex and it's pretty great, though I noticed that it doesn't look at all smooth in T3D unless you do this (i.e. use ScriptTickObject and its callback).

It worked fine for simple GUI object movement - I made roll-out button panels that sit on the edges of the screen. I'll have to upload a short video later.

I've been contemplating translating this to C++ myself. It's a natural progression and as Daniel points out it's a better overall solution for T3D.

Link to comment
Share on other sites

Thats cool, could be used for doors/windows/... evrything

would just need things like keylock/unlock and for windows a setting ifbroken = isopen and we could use potentially evry shape without the need of animating it. I can see the value of this, it could be used for cutscenes as well (that would need some more work and maybe a lookup at gmk cutscenes or verve on pointers how to combine this)

Link to comment
Share on other sites

It worked fine for simple GUI object movement - I made roll-out button panels that sit on the edges of the screen.

That's exactly what I was doing, and they didn't look smooth until I made those changes.

Weird - I'll try to get a video posted...

https://github.com/RichardRanft/Project13

They're not silky smooth, but they are acceptable in my book. The bottom panel is not moving as far, so it looks pretty smooth, but the side panels are a little noticeable if you watch them closely.

And I forgot that I modified GameTSCtrl and added an onResize() callback. Anyway, should be okay as long as you don't resize the window....

Link to comment
Share on other sites

  • 2 weeks later...

Lukas:


I got this error trying to compile:

 

16>c:\torque\363_vehiculo\engine\source\console\consoleobject.h(620): error C2259: 'Tween' : cannot instantiate abstract class
16>          due to following members:
16>          'void ITickable::interpolateTick(F32)' : is abstract
16>          c:\torque\363_vehiculo\engine\source\core\itickable.h(113) : see declaration of 'ITickable::interpolateTick'
16>          'void ITickable::processTick(void)' : is abstract
16>          c:\torque\363_vehiculo\engine\source\core\itickable.h(117) : see declaration of 'ITickable::processTick'
16>          c:\torque\363_vehiculo\engine\source\console\consoleobject.h(620) : while compiling class template member function 'ConsoleObject *ConcreteClassRep<T>::create(void) const'
16>          with
16>          [
16>              T=Tween
16>          ]
16>          c:\torque\363_vehiculo\my projects\vehiculo363\source\t3d\tween.h(61) : see reference to class template instantiation 'ConcreteClassRep<T>' being compiled
16>          with
16>          [
16>              T=Tween
16>          ]

 

did I need to change consoleObject?

Link to comment
Share on other sites

Lukas:


I got this error trying to compile:

 

16>c:\torque\363_vehiculo\engine\source\console\consoleobject.h(620): error C2259: 'Tween' : cannot instantiate abstract class
16>          due to following members:
16>          'void ITickable::interpolateTick(F32)' : is abstract
16>          c:\torque\363_vehiculo\engine\source\core\itickable.h(113) : see declaration of 'ITickable::interpolateTick'
16>          'void ITickable::processTick(void)' : is abstract
16>          c:\torque\363_vehiculo\engine\source\core\itickable.h(117) : see declaration of 'ITickable::processTick'
16>          c:\torque\363_vehiculo\engine\source\console\consoleobject.h(620) : while compiling class template member function 'ConsoleObject *ConcreteClassRep<T>::create(void) const'
16>          with
16>          [
16>              T=Tween
16>          ]
16>          c:\torque\363_vehiculo\my projects\vehiculo363\source\t3d\tween.h(61) : see reference to class template instantiation 'ConcreteClassRep<T>' being compiled
16>          with
16>          [
16>              T=Tween
16>          ]

 

did I need to change consoleObject?

 

Ohh right.. I may have edited the code a little prior to uploading... It's because I forgot that you have to implement all the ITickable functions. I.e. ProcessTick InterpolateTick and AdvanceTime. Where I only implemented one.. Just create empty implementations for ProcessTick and InterpolateTick.. I'll edit the code :P

Link to comment
Share on other sites

@LukasPJ:


per your suggestion adding this at line 22, exactly as in Impact, worked!

 

   virtual void interpolateTick( F32 delta ) {};
  virtual void processTick() {};

 


...I'll have to edit the video tonight after work but I've setup a scripted turret using the 'deathball desert' shapes - nice 'n fun...

Link to comment
Share on other sites

@LukasPJ:


Can you help me with something? I have the old 'deathball desert' turrets working entirely in script. The only thing I've lacked has been a way to smooth out the movement. I'd like to use a Tween for this, but I'm not sure I'm setting it up correctly.


here's my little function:

 

function aimTurret(%turret)
{
   %target = %turret.target;
   echo("stationTurretTrigger::aimTurret %turret "@%turret@" target "@%target);
 
   if(isObject(%target))
   {
      echo("stationTurretTrigger::aimTurret %target valid");
      %turretPos = %turret.getPosition();
      %tgtPos = %target.getPosition(); 
      // this function returns the rotation '%rot' needed to point the turret at its target     
      %rot = pointToPos(%turretPos, %tgtPos);
 
      if(%turret.tween !$= "")
      {
         %turret.tween.delete();
         %turret.tween = "";
      }
 
      %turret.tween = new Tween()
      {
         Duration = 1; // This is in seconds.
         Target = %turret; // Any SimObject.
         ValueName = "r"; // "r" for rotation?
         ValueTarget = %rot; // should I be placing the destination rot value here?
         EaseDirection = $Ease::Out; // This is just the stock easing values.
         EaseType = $Ease::Circular; // Again, this is a stock thing, I didn't implement the $Ease enum.
      };
 
      echo("stationTurretTrigger::aimTurret %tween: "@%turret.tween);
      %turret.tween.play();
      // need an 'onFinished' call here to fire the weapon...
 
   }
}

 

My other question is how to setup the 'onFinished' call - I want to pull the turret's trigger as soon as the tween is finished...

Link to comment
Share on other sites

@Gibby unfortunately, it's a fairly simple class atm so you'd need one tween for each axis the turret needs to rotate on. I might improve this later on :)

This is written by hand so there maybe syntactical issues:

function aimTurret(%turret)
{
   %target = %turret.target;
   echo("stationTurretTrigger::aimTurret %turret "@%turret@" target "@%target);
 
   if(isObject(%target))
   {
      echo("stationTurretTrigger::aimTurret %target valid");
      %turretPos = %turret.getPosition();
      %tgtPos = %target.getPosition(); 
      // this function returns the rotation '%rot' needed to point the turret at its target     
      %rot = pointToPos(%turretPos, %tgtPos); 
 
      if(%turret.tween !$= "")
      {
         %turret.tween.delete();
         %turret.tween = "";
      }
 
      %turret.tween = new Tween(TurretTween)
      {
         Duration = 1; // This is in seconds.
         Target = %turret; // Any SimObject.
         ValueName = "rz"; // "r" for rotation, "z" for axis
         ValueTarget = %rot.z; // should I be placing the destination rot value here?
         EaseDirection = $Ease::Out; // This is just the stock easing values.
         EaseType = $Ease::Circular; // Again, this is a stock thing, I didn't implement the $Ease enum.
 
         // Dynamics
         Turret = %turret; //Wooh circular references!
      };
 
      echo("stationTurretTrigger::aimTurret %tween: "@%turret.tween);
      %turret.tween.play();
   }
}
 
function TurretTween::onFinished(%this)
{
    %this.turret.fire-away_fire-away();
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...