Game Development Community

Paths

by J Sears · in Torque Game Builder · 04/23/2007 (8:23 pm) · 4 replies

I read through the tgb doc and found the paths tutorial, easy to understand could do that stuff fine. What I want is for my card dealing animation is to set up paths to the players spots, spawn cards on those spots and deal them out to the players to make it look like it's dealing (even though the hand has already been delt out and decided, this is just for looks).

So it tried something like this first
%objCount = t2dScene.getSceneObjectCount();
%objList = t2dScene.getSceneObjectList();


  for(%i=0;%i<%objCount;%i++)
   {
          %obj=getWord(%objList,%i);
          if(%obj.isPath == 1 && %obj.pathNumber == 1)
          {
	   %path=%obj;
           }

   }

    %path.attachObject(%card, 30 , 1 , 1 , 0 , "WRAP" , 1 , false);

I defined the isPath and pathNumber in TGB as fields in the path so I could find it in the search. %card I tried doing 2 ways. I tried creating a new static sprite without giving it a specific location to be created and then hoping it would be attached to the path with that command at the end, card never showed up. I also tried having the card be off screen and be part of the level creation.
The strange thing is when I do it that way and run attachobject, the card comes from off screen towards the first node then when it hits the first node goes to the next one and stops (I have it stop on purpose with the 1 for loop). I thought attachObject would actually attach the card to the path not make it travel to the path and then attach it to the path. These were my experiments to get a handle on paths in script so I could get my deal animation under way. I searched through the path reference for any other commands but this seems to be the only one.
I also tried in desperation to mount the card to the path and then run attach object but the mount command mounts it to the middle of the path between the two nodes not on one of them.

#1
04/24/2007 (5:14 am)
The last parameter of attachObject is sendToStart. You should set this to "true" if you want the object on attachment to the path to begin at the start node rather than moving from its current location.
#2
04/24/2007 (8:58 am)
J -- depending on the complexity of your paths ... there may be a nicer way to go about doing this ... if your just taking the cards from a central location, and want them to move to the players card location ... paths are nice, if you want to add some movement into the mix ... such as zig-zag or a rounded arc movement or something ... but if your just looking to do a simple 'move to card slot' ... you could utilize the t2dSceneObject.moveTo() function ... which will move your card from where ever it is currently, to the location you specific ...at the speed you specify ... so ... to make it feel more natural, like it's being dealt by a real person ... you could have a random number generator determine your speed ... so that some cards go fast, some go faster, and some go slower ... the moveTo also has a callback that is generated, that lets you know that the object has reached it's destination, this could be used, for example ... to time your card hand outs ... maybe toss 2-3 cards down at a time, and wait to deal the 4th until the first reaches it's destination, so you don't have cards overlapping in movement (due to random speeds, it could happen)


#3
04/24/2007 (10:38 am)
Thank you Gary silly for me to miss something that simple.

@David that sounds like a better way to do it then I was going to with the paths, thanks again I will check out that function
#4
04/24/2007 (10:42 am)
J -- the path thing is cool, only if you want to have 'nodes' in the movement ... you could dynamically build the path through script, so that each card had it's own custom 'node route' ... and make the routes sort of arc'd ... so the cards had a smooth rounded movement to them ... like if you wanted to make the card look like it was hopping up then down ... you could shrink the card as it headed toward the center node ... then enlarge the card as it moved toward the end node ... but that's just unnecessary 'flare' ... ;)