LukasPJ Posted February 17, 2015 Share Posted February 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
rlranft Posted February 17, 2015 Share Posted February 17, 2015 Nice - I snagged Charlie's Twillex stuff from T2D, but so far all I've used it for is some GUI stuff.... Quote Link to comment Share on other sites More sharing options...
Steve_Yorkshire Posted February 17, 2015 Share Posted February 17, 2015 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. Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 17, 2015 Author Share Posted February 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
Steve_Yorkshire Posted February 17, 2015 Share Posted February 17, 2015 @LukasPJTwillex? I thought that was a dubstep DJ or someone ...Library.cs is an ancient file or TorqueScript which predates the Phanerozoic Era by half a billion years. It's full of fancy script utilities and mathematics before TGE had them integrated into C++ and the like.http://yorkshirerifles.com/downloads/library.cs Quote Link to comment Share on other sites More sharing options...
rlranft Posted February 17, 2015 Share Posted February 17, 2015 "Tweening" - from "in between keyframes," it means to draw the animation frames between the keys provided - or "inbetweening." See http://en.wikipedia.org/wiki/InbetweeningTwillex - Scripts to aid simple animation sequences in T2D. See http://www.garagegames.com/community/blogs/view/21480 Quote Link to comment Share on other sites More sharing options...
buckmaster Posted February 19, 2015 Share Posted February 19, 2015 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). Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 19, 2015 Author Share Posted February 19, 2015 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).This is a C++ version of Twillex so it's pretty smooth already :P Quote Link to comment Share on other sites More sharing options...
RichardM Posted February 19, 2015 Share Posted February 19, 2015 Nice! Quote Link to comment Share on other sites More sharing options...
rlranft Posted February 19, 2015 Share Posted February 19, 2015 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. Quote Link to comment Share on other sites More sharing options...
buckmaster Posted February 19, 2015 Share Posted February 19, 2015 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. Quote Link to comment Share on other sites More sharing options...
J0linar Posted February 19, 2015 Share Posted February 19, 2015 Thats cool, could be used for doors/windows/... evrythingwould 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) Quote Link to comment Share on other sites More sharing options...
rlranft Posted February 19, 2015 Share Posted February 19, 2015 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/Project13They'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.... Quote Link to comment Share on other sites More sharing options...
buckmaster Posted February 20, 2015 Share Posted February 20, 2015 Well, I wanted silky smooth, and I got it ;).Having a window resize callback is a very good idea. I think @Azaezel proposed it a while back. Not sure what happened to the idea. Quote Link to comment Share on other sites More sharing options...
Gibby Posted February 28, 2015 Share Posted February 28, 2015 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? Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted March 1, 2015 Author Share Posted March 1, 2015 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 Quote Link to comment Share on other sites More sharing options...
Gibby Posted March 1, 2015 Share Posted March 1, 2015 @Lukas: Thanks! Quote Link to comment Share on other sites More sharing options...
cybore Posted March 4, 2015 Share Posted March 4, 2015 Could this be used for moving platform objects? If so, is there any "known" problems with collisions? Quote Link to comment Share on other sites More sharing options...
buckmaster Posted March 4, 2015 Share Posted March 4, 2015 Yes: they don't work. :P Quote Link to comment Share on other sites More sharing options...
Gibby Posted March 4, 2015 Share Posted March 4, 2015 @cybore:what you want is this:http://www.garagegames.com/community/forums/viewthread/137542 Quote Link to comment Share on other sites More sharing options...
rlranft Posted March 4, 2015 Share Posted March 4, 2015 Oh man, moving platforms - another thing you'd think would be easy.... Quote Link to comment Share on other sites More sharing options...
Gibby Posted March 4, 2015 Share Posted March 4, 2015 @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... Quote Link to comment Share on other sites More sharing options...
cybore Posted March 4, 2015 Share Posted March 4, 2015 Awesome! Thank you for pointing this out Gibby! Quote Link to comment Share on other sites More sharing options...
Gibby Posted March 5, 2015 Share Posted March 5, 2015 @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... Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted March 5, 2015 Author Share Posted March 5, 2015 @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(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.