Forward movement only and script classing...
by Josh Moore · in Torque Game Builder · 10/04/2007 (11:19 am) · 1 replies
I'm having trouble with two little code hitches that reside in the TGB source core. For one, I don't understand why when using forward movement only, you can't use a negative force to go in reverse. Looking at the console function it seems as just commenting out the return in the minimum value check would allow the pyhsics code to use a negative value, but it doesn't.
The only thing I actauly figured out is that if I remove the minus from this code, the object will only go backwards. Is there anyway to allow for forward & backward movement while still limiting lateral movement?
Next, I've been looking into this for a while; Lets say I have a chain of Script classes(Ship->Vehicle->DynamicObj->SceneObject), and I'm using them with the proper Parent:: function linking that's available in TS. However, I have no way of checking if object X is of class N, R, Y, or G. There is the console method .isMemberOfClass, but this only looks for the C++ classes(aka t2dSceneObject) rather than my script defined class(es). I tried messing with that function, but I ended up getting it to print every damn Namespace and it's fields to the Console.
Currently I can only check the object's class or super class the normal way(%obj.class $= "Ship" || %obj.superClass $= "Vehicle"), but going that route just doesn't let me check for the higher level classes. Idealy I'd just like to be able to do something like
Is something like that even possible at all?
Thank you for barring with me, I hope you guys can shead some light on this stuff.
-Josh
// Are we doing forward movement only?
if ( mForwardMovementOnly )
{
// Yes, so calculate forward vector.
const t2dVector forwardVec(0.0f, -getGrossLinearVelocity().len() * elapsedTime);
// Integrate new position.
setPosition( getPosition() + (forwardVec * getRotationMatrix()) );
}The only thing I actauly figured out is that if I remove the minus from this code, the object will only go backwards. Is there anyway to allow for forward & backward movement while still limiting lateral movement?
Next, I've been looking into this for a while; Lets say I have a chain of Script classes(Ship->Vehicle->DynamicObj->SceneObject), and I'm using them with the proper Parent:: function linking that's available in TS. However, I have no way of checking if object X is of class N, R, Y, or G. There is the console method .isMemberOfClass, but this only looks for the C++ classes(aka t2dSceneObject) rather than my script defined class(es). I tried messing with that function, but I ended up getting it to print every damn Namespace and it's fields to the Console.
Currently I can only check the object's class or super class the normal way(%obj.class $= "Ship" || %obj.superClass $= "Vehicle"), but going that route just doesn't let me check for the higher level classes. Idealy I'd just like to be able to do something like
if(%obj.isMemberOfClass("DynamicObj")) {
if(%obj.isMemberOfClass("Ship") {
..... Do This .....
}
else if(%obj.isMemberOfClass("Plane") {
.... Do That ....
}
}Is something like that even possible at all?
Thank you for barring with me, I hope you guys can shead some light on this stuff.
-Josh
Torque 3D Owner baylor wetzel
You have two types of classes of interest. The first is the physical/concrete/implementation/engine whatever classes like SimObject, ScriptObject, SimGroup, t2dSceneObject, etc. These objects make things happen but are completely independent of game logic. There are no objects of this type that are ships, bullets, player, etc. The second kind are the logical/game-specific/script-created objects like player, alien, asteroid, ball, etc. These are part of the game logic and always implemented through some concrete object (t2dStaticSprite, ScriptObject, etc.). These are the only kinds of objects the game logic cares about
In theory, an object can have a pseudo-class heirarchy of PlayerShip->Ship->Vehicle->t2dStaticSprite->SimObject (or whatever) where the first three are basically just tags/descriptors (stored in dynamic variables called name, class and superclass), not really classes, are are represented in script and the latter two are actual honest to goodness classes with inheritance, C++ classes and the like. The latter classes are real classes while the former are more like interfaces (sorta), as in my object implements/uses the functionality of Ship and Vehicle. In this case, stating that one is the class and the other the superclass simply denotes the order that the "interfaces" are checked
The point being that the "classes" you're looking at are two different things and so must be checked in different ways
So i don't *think* there's a way to check both types of classes with a single built-in function. That's the bad news. The good is that you could always write a function to do it. You could override isMemberOfClass in SimObject to do both types of checks. i'm not sure how you'd call the parent method though (i should learn if that's possible). So what i typically do is create a similar method with a slightly different name. In this case, i suppose it would be
function SimObject::isMemberOfExtendedClass(%this, %className) { if (%className $= %this.class) return true; if (%className $= %this.superclass) return true; return %this.isMemberOfClass(%className); }i did that off the top of my head because i've never thought to have a function like this before. The reason being, i can't personally think of a reason why you'd want to search the merged space of game logic classes and implementation classes. Meaning, i never need to say "if you're an asteroid or if you're an animated sprite". But if that's valuable to you, i think the above method ought to do it