Game Development Community

Constant force on platform

by Wenceslao Villanueva Jr. · in TGB Platformer Kit · 05/03/2008 (7:46 pm) · 3 replies

This all started when I installed the TGB 1.7.3 Beta but I've since uninstalled it, uninstalled TGB 1.7.2 and the PSK and then reinstalled TGB 1.7.2 and the PSK. With 1.7.3 I opened one of my platformer projects but NEVER converted it.

When I set the constant force of a platform to anything negative (to make a conveyor belt for example) it seems to work fine. But when I set the constant force of any platform to positive, it has effects on the actor's movement while on the platform but when the actor stands still, the platform does not affect the actor. What's really messed up is that ALL of this used to work fine, then I noticed it

I've nailed it down to this function in GameMethods.cs:

function mVectorMultiply(%vA, %vB)
{
	%x = (%vA.X * %vB.X);
	%y = (getWordCount(%vB) > 1) ? (%vA.Y * %vB.Y) : (%vA.Y * %vB.X);
	
	return %x SPC %y;
}

when it's called in side the function ActorBehavior::updateOnGroundPhysics(%this) when calculating
if (%gNormal.Y > 0)
		%mVector = mVectorMultiply(-%gNormal.Y SPC %gNormal.X, -%this.MoveSpeed.X + %externalForce);
	else
		%mVector = mVectorMultiply(-%gNormal.Y SPC %gNormal.X,  %this.MoveSpeed.X + %externalForce);

Here's what's really messed up. So in mVectorMultiply %vA is a vector and %vB is a constant (as updateOnGroundPhysics calls it. In calculating %x, it multiplies %vA.X times %vB.X
The problem is, %vB is a constant isn't it? So why would it have a field X?
Here's where my investigation really gets messed up, in Torsion, hover over %vB.X when %vB is positive, it just shows empty quotes: "" Which is what I expect. If %vB is negative, and hover over it, it shows that %vB.X = -10.

What the hell is going on? This all USED to work (I haven't messed with any of the PSK code, only have added some of my own behaviors). But according to my evaluation it shouldn't of worked ever because %vB.X should = "" always (unless I'm totally missing something). To violate my expectations more, the script is working counter to what I thought it should do.

Can anyone throw me a bone? It's driving me batty, I already uninstalled TGB and PSK and reinstalled them and nothing. I've even taken the behaviors I created out for the time being.

#1
05/03/2008 (7:56 pm)
The plot thickens...

If I set the constant force of a platform to 40, 20, 15 or 1, it all seems to work just fine.

If I set it to 8, 9 or 10 it doesn't work.

I get the feeling that something has horribly gone wrong. I'm going to wipe TGB again, reboot, wipe the directories, do a registry scrub and see what happens.

Update: No change. I'm pretty sure I'm just not understanding something. I still have no explanation for what's going on.
#2
05/03/2008 (9:13 pm)
The "mVectorMultiply" is used to multiply two vectors or scale a vector by a constant. If %vB has two words in it, then it will multiply the two vectors, otherwise it will scale the first vector by the constant. If you have a ".x" on the end of a variable, it will return the first word in the variable, no matter it's contents. To verify, try typing this in the console:

$a = "1 2 3";
$b = "4";
echo ($a.x SPC $a.y SPC $a.z); // Result in 1_2_3 (where _ is a space)
echo ($b.x SPC $b.y SPC $b.z); // Result in 1__

Anyways, on to the problem at hand! It appears that there is a bug with the whole ".x .y .z" thang. I will throw up a bug post in the TGB forum, I do not think that is relates to 1.7.3 only, I think it has been a problem since 1.5.

For a quick fix change your function to this:

/// %vA = 2d vector; %vB = int/2d vector
function mVectorMultiply(%vA, %vB)
{
	%x = (getWordCount(%vB) > 1) ? (%vA.X * %vB.X) : (%vA.X * %vB);
	%y = (getWordCount(%vB) > 1) ? (%vA.Y * %vB.Y) : (%vA.Y * %vB);
	
	return %x SPC %y;
}
#3
05/03/2008 (9:35 pm)
Thanks for the reply Phillip!

Heh, I was about to post that I still had no idea what was going on but I ended up just writing the same code you just did. It fixes the issue but I'm really bad at letting problems linger and I wanted to get a handle as to what was going on. I didn't want it coming back to plague me later. Thanks for your help, I'm greatful that I'm not crazy.

I was waiting for this video to clear before I posted a response but since I posted it anyways, here's video of the issue in case everyone on the forums thought I was a looney: www.youtube.com/watch?v=t9XIdlYs7ZU

The rad part is that a value of 10 has worked for a LONG time. It just recently broke which is the part that drives me nuts.

edit: My video was spliced together incorrectly so I edited it.