Game Development Community

[SOLVED]need a little help with control statement "if"

by Vlad I · in Torque Game Builder · 11/08/2011 (6:13 am) · 16 replies

Sorry for noob question. I need help with control statement, a bit confused.
I have an object moving on a path starts on node 2, goes straight then goes up , it moves to top node 3 where it gets reversed and flips axe Y, it goes back to node 2. So if you imagine a scorpion crawling on the window to the wall then goes up hits the ceiling and goes back.(it is looped)

It all works except one problem, flipping in pathing is a bit weird on reverse it always flips so if you have a path like I described above the scorpion goes back upside down and you need to adjust setFlip all the time.

So I dont want control statement "if" to take place at the very first start but only afterwards, what should I use? have a look at the script:

function Scorpion05::onLevelLoaded(%this, %scenegraph)
{
p4.setRotationOffset(sc5, 90);
P4.attachObject(Sc5, 5, -1, 2, 3, "reverse", -1, true);
}
function ScPath04::onReachNode(%this, %object, %node)
{
if(%node $= 3)
{
sc5.setFlipY(true);
P4.setSpeed(Sc5, getRandom(9, 10), false);
}
//I dont want it to flip at the very start I want it to flip on the way back
if(%node $= 2)
{
sc5.setFlipY(true);
}
}

#1
11/08/2011 (12:33 pm)
I didn't test but does this help?
function Scorpion05::onLevelLoaded(%this, %scenegraph)
{ 
	p4.setRotationOffset(sc5, 90); 
	P4.attachObject(Sc5, 5, -1, 2, 3, "reverse", -1, true); 
}
function ScPath04::onReachNode(%this, %object, %node)
{ 
	if(%node $= 3) 
	{ 
		sc5.setFlipY(true); 
		P4.setSpeed(Sc5, getRandom(9, 10), false);
	}
	//I dont want it to flip at the very start I want it to flip on the way back
	if(%node $= 2) 
	{ 
		if(P4.getMoveForward(Sc5) == false)
		{
			sc5.setFlipY(true); 
		}
	}
}
#2
11/08/2011 (11:20 pm)
Hi Patrick !
I'm trying your script it only makes one flip at all, at the start .

I have a feeling, every time start or end node forces my object to flip Y no matter what I can not controll it, just like that bug with new speed which was sending my object to the start node.
So when it is reversed and goes back to start node it flips again.

And sc5.setFlipY(true); only works once.
#3
11/09/2011 (12:49 am)
Yes, it looks like flipping works only once.
#4
11/09/2011 (5:44 am)
Vlad, I'm confused again about what you're trying to do. If I don't force it to flip by removing the check on node 2, it seems to move as I'd expect - with the object aligned to the path and flipping when it changes direction.
function p4::onReachNode(%this, %object, %node)
{ 
	if(%node == 3) 
	{ 
		p4.setSpeed(sc5, getRandom(9, 10), false);
	}
}
#5
11/09/2011 (5:52 am)
It is a bit hard to explain. I can send you my project if you care to look into it , it might poure some light on it.
#6
11/09/2011 (5:53 am)
Sure. patrickadesso gmail
#7
11/09/2011 (6:12 am)
is it patrickadesso(at)gmail(dot)com ?

Mail delivery failed
#8
11/09/2011 (6:13 am)
It is. Try renaming the zip to piz.
#9
11/09/2011 (6:18 am)
ok I think it's been sent.
#10
11/09/2011 (6:19 am)
double post
#12
11/09/2011 (6:28 am)
Vlad, you're starting at node 2 and ending at node 3 (as defined in your attachObject call. So use this:
if(%node == 2) 
   { 
      echo("At node 2"); 
      sc5.setFlipY(false); 
   }  
   
   if(%node == 3) 
   { 
      echo("At node 3"); 
      sc5.setFlipY(true); 
   }

Cool?!
#13
11/09/2011 (6:39 am)
haha ! Thank you !!! Damn I always get confused on these things : which has to go first and which has to go next :)
You are the best!!!
#14
11/09/2011 (6:41 am)
No problem! When working with paths like that, I sometimes will drag out some text objects as node labels to help me visually keep track of what's going on.

Good luck!
#15
11/09/2011 (6:41 am)
btw how do you paste your code here with numbers and the greem line, I have Torsino too.
#16
11/09/2011 (6:42 am)
See in the box where you add a reply, there is a link that says "MarkupLite is Enabled".

Click that and it will explain how to do bold,
code
and all sorts of other stuff.