Game Development Community

Object doesnt reverse on Path

by Vlad I · in Torque Game Builder · 11/04/2011 (2:32 am) · 24 replies

I have an object mounted on a path wich doesnt reverse upon reaching a node why?
Upon reaching node 2 it gets stuck and sort of twitches. No errors in the console.
All I'm trying is to make my scorpion move from left to right on a path with random speed upon reaching a node.

function Scorpion05::onLevelLoaded(%this, %scenegraph)
{
P4.attachObject(Sc5, 5, 1, 0, 2, "reverse", -1, false);
}

function ScPath04::onReachNode(%this, %object, %node)
{
if(%node $= 2)
{
P4.setSpeed(Sc5, getRandom(1, 10));
}
}


Also I have another question. When you mount an object on a path you can set Rotation Offeset in Pathing in TGB editor.
How can I do it from the script?
smth. setRotationOffeset(90); ?
Page «Previous 1 2
#1
11/04/2011 (5:56 am)
Quote:
Upon reaching node 2 it gets stuck and sort of twitches.
Are you setting a new node target?

Quote:
Also I have another question. When you mount an object on a path you can set Rotation Offeset in Pathing in TGB editor.
How can I do it from the script?
smth. setRotationOffeset(90); ?
Yes, that seems correct but you have a typo in the name:
setRotationOffset(90);
#2
11/04/2011 (7:03 am)
Hi Patrick
Thank you for helping me.
No that is all I have for my function. Do I need to set a new node target? How do I do it.
I thought it will reverse it node by node backwards, I cant find setNewNode in the reference.

Also, can the changing of speed on reaching node 2 somehow block/stop the object go reverse.
It looks to me that the function is executed from the start in a loop and always gets start from node 0, so when it receives new command to change speed it starts from node 0 and when I change my path from WRAP to REVERSE I get a bug. That is why it stops on node 2 and twitches ,it is sort of trying to get back to node 0 to start the cycle with new speed, but cant since onReachNode callback, I got REVERSE. Am I right on this one?

Also where do I put setRotationOffset(90);
#3
11/04/2011 (7:26 am)
Btw when I define follow mode as WRAP it goes in circle, node by node and when reaches node 2 restarts on node 0 with new random speed. Is there any way to make it change the speed and continue moving on the path instead of restarting it back to the start node. Looks like the new random speed sends object back to the start node and the new speed is applied.
#4
11/05/2011 (7:40 am)
Hey Vlad, sorry about the delay; been hectic around here!

I'm not exactly sure what you're trying to do but try this out:
%this.attachObject(pathObject, 5, 1, 0, 2, "reverse", 0, true);
When I tried -1 for the "loops" parameter in the attachObject method, I got that twitchy-ness you were talking about. Also, I set the last parameter (sendToStart) to false because when I set it to true, it seems that the attached object proceeds to node 2, then back to 1, then properly follows the path.

If I'm off base, let me know and I can test some other things. If it gets too project specific; you can email me as well. patrickadesso {at} gmail -dot- com.
#5
11/05/2011 (7:59 am)
I think you only tried the attachObject function.Unless there is a misunderstanding.
Have you tried it with:
function ScPath04::onReachNode(%this, %object, %node)
{
if(%node $= 2)
{
P4.setSpeed(Sc5, getRandom(1, 10));
}
}
If I do just:
function Scorpion05::onLevelLoaded(%this, %scenegraph)
{
P4.attachObject(Sc5, 5, 1, 0, 2, "reverse", -1, false);
}

it works no matter if it is false or true or loops -1 or 1 or zero.
But the problem (the twitchness) becomes when I use onReachNode ,- I want to have random speed.
Can you check this code please if it doesnt bother too much:
function Scorpion05::onLevelLoaded(%this, %scenegraph)
{
P4.attachObject(Sc5, 5, 1, 0, 2, "reverse", -1, false);
}

function ScPath04::onReachNode(%this, %object, %node)
{
if(%node $= 2)
{
P4.setSpeed(Sc5, getRandom(1, 10));
}
}
you will need to create a path in the editor with 3 nodes.
I think that onReachNode conflicts with the path.
Btw I tried your line , I still get twitchness
#6
11/05/2011 (8:22 am)
Sorry about that...

So here is what I tested; pardon the name changes, I had my test project setup differently, but it should be clear.
function testPath::onLevelLoaded(%this)
{
   echo(%this SPC "loaded");    
   pathObject.setMaxAngularVelocity(2);
   %this.attachObject(pathObject, 5, 1, 0, 2, "reverse", 0, false); 
}

function testPath::onReachNode(%this, %object, %node)
{
   if(%node $= "2")
   {
      testPath.setSpeed(pathObject, getRandom(1, 10));
   }
}

It looks like it's getting to node 2, just passing it, then reversing. Again, reaching node 2, again reversing and getting stuck in a loop there.

Sorry Vlad, I completely missed this statement:
Quote:
All I'm trying is to make my scorpion move from left to right on a path with random speed upon reaching a node.

Try this:
function testPath::onLevelLoaded(%this)
{
   echo(%this SPC "loaded");    
   pathObject.setMaxAngularVelocity(2);
   %this.attachObject(pathObject, 5, 1, 0, 2, "REVERSE", 0, true); 
}

function testPath::onReachNode(%this, %object, %node)
{
   //we've reached the end
   if(%node == %this.getNodeCount())
   {
      %this.setMoveForward(pathObject, false);
   }
}
#7
11/05/2011 (8:34 am)
you removed random speed
if(%node $= 2)
{
P4.setSpeed(Sc5, getRandom(1, 5));
}

trying to add it so far still twitching
#8
11/05/2011 (9:00 am)
Hey!

So I did some testing with setSpeed and am in complete agreement with you. No matter what I do, the obejct resets when you assign it a new speed.

So, I opened up the source and took a look at what was going on and sure enough whenever setSpeed is called, an internal method is also called that sends the object back to the start.
if (pathedObject) pathedObject->setSpeed(speed, true);
Now you don't have a pro license so you can't even fix this issue but the way I see it this is a very wrong way to handle it.

I recommend you submit a bug about this and hopefully it'll be fixed in the next version. In the meantime, I'm going to see if I can mod the source and build a new exe that you can use.

Hold tight.
#9
11/05/2011 (9:00 am)
Im trying to use your code with slight difference:

function Scorpion05::onLevelLoaded(%this, %scenegraph)
{
P4.attachObject(Sc5, 5, 1, 0, 2, "reverse", 0, true);
}

function ScPath04::onReachNode(%this, %object, %node)
{
if(%node == %this.getNodeCount())
{
P4.setSpeed(Sc5, getRandom(1, 5));

}
}
It does go reverse on node 2 but doesnt change the speed the object that is moving on the path , no errors.
#10
11/05/2011 (9:01 am)
Just saw this thread... looks like the change didn't make it in there:
link
#11
11/05/2011 (9:03 am)
Before I do this... You're on Windows right?
#12
11/05/2011 (9:09 am)
Yeah that is what I thought from the very start , you didnt read what I typed in my second reply did you ;) . Yes I'll submit the bug , the twitching itself is a proof :)
Thanks , it's been a nice to have a decent conversation about it, I understod what you were trying to do with that :

if(%node == %this.getNodeCount())
{
%this.setMoveForward(pathObject, false);
}
But doesnt help too. So I guess if it cant be fixed in the source then we'll have to wait for a fix. It is definetly useful. Meanwhile I made a workaround by using onWorlLimt but it only works on straigh lines, so if I want to have my Scorion moving around I'd have to wait for the fix.
Btw if you find a way to fix it in the source I'm gonna have to buy a Pro version :)
Thanks Patrick , you are legend
#13
11/05/2011 (9:10 am)
I can provide you a new exe with the fix but only if you're on Windows... I barely know how to use a Mac, much less XCode.
#14
11/05/2011 (9:11 am)
yes XP
#15
11/05/2011 (9:14 am)
It would be great, much appreciated
#16
11/05/2011 (9:37 am)
OK, all set...

Download the file here.

Extract the exe and copy it to your game directory. Delete the exe in there and change the name of Test.exe to whatever the name of your exe was.

Then modify your setSpeed call to look like so:
path.setSpeed(pathObject, %newSpeed, false);

Sorry about the confusion before. Let me know how it goes!
#17
11/05/2011 (10:05 am)
Yes it works, you are the best! with my old script just added false as you pointed ,no errors :)
#18
11/05/2011 (10:13 am)
Just last question , where do I add
setRotationOffset(90);
I cant find setRotationOffset in the documentaion
#19
11/05/2011 (10:39 am)
Very happy to help and glad it's working for you! These are the trial of tribulations of using TGB I guess. I love to hate it! :)

So setRotationOffset isn't anywhere in the docs that I can see but it certainly exists in the TGB 1.7.5 source. You use it like so:
path.setRotationOffset(pathObject, 90);

Do you know about the dump() function? In your console (press ` while running your game) then you can call objectNameOrClass.dump() and it will list all functions associated with it. It's kind of a mess but at least it's more current than the docs.
#20
11/05/2011 (10:54 am)
Thank you again, I think I need to buy the source :)
I thought just this line:
setRotationOffset(90);
would do the trick , I was wrong . TGB makes you think ! :)
Page «Previous 1 2