Game Development Community

Gravity on different objects

by Mitchell Talmadge · in Torque 3D Professional · 06/27/2011 (6:41 am) · 9 replies

I was wondering if anyone has gotten this resource: http://www.garagegames.com/community/resource/view/1723
to work in Torque 3D. I'm making a space simulation game with planets and I need a gravity modifier for players/vehicles/other objects.


Thanks!

About the author

I have been scripting mods for a game called "Blockland" and I decided to take a shot at making my own game. I am currently working on my own game titled "Celestial Online".


#1
06/27/2011 (10:21 am)
As I recall, there were a couple of fiddly bits that had to be adjusted... but it worked in a previous Beta, so should be no reason why it wouldn't work in Final. What kind of error(s) are you getting?
#2
06/27/2011 (6:01 pm)
Well I was just noticing how there was a lot of code that isn't there anymore. Such as:

Quote:
Find the function "void ShapeBase::consoleInit()" Scroll down until you see:
------------
Con::addCommand("ShapeBase", "getEyeVector", cGetEyeVector, "obj.getEyeVector()", 2, 2);
Con::addCommand("ShapeBase", "getEyeTransform", cGetEyeTransform, "obj.getEyeTransform()", 2, 2);

Con::addCommand("ShapeBase", "setEnergyLevel", cSetEnergyLevel, "obj.setEnergyLevel(value)", 3, 3);
Con::addCommand("ShapeBase", "getEnergyLevel", cGetEnergyLevel, "obj.getEnergyLevel()", 2, 2);
------------


In the space between insert the following:
------------
Con::addCommand("ShapeBase", "setGravity", cSetGravity, "obj.setGravity(value)", 3, 3);
Con::addCommand("ShapeBase", "getGravity", cGetGravity, "obj.getGravity()", 2, 2);
------------

But all that is in the function is:

Con::addVariable("SB::DFDec", TypeF32, &sDamageFlashDec, "Speed to reduce the damage flash effect per tick.\n\n"
      "@see ShapeBase::setDamageFlash()\n"
      "@see ShapeBase::getDamageFlash()\n"
      "@note Relies on the flash postFx.\n"
	   "@ingroup gameObjects\n");
   Con::addVariable("SB::WODec", TypeF32, &sWhiteoutDec, "Speed to reduce the whiteout effect per tick.\n\n"
      "@see ShapeBase::setWhiteOut()\n"
      "@see ShapeBase::getWhiteOut"
      "@note Relies on the flash postFx.\n"
	   "@ingroup gameObjects\n");
#3
06/27/2011 (6:21 pm)
The "missing" code you mentioned: getEyeVector(), getEyeTransform(), etc., have been switched to the new DefineEngineMethod functions.

As I mentioned above there will be a small bit of wrenching needed to make it work. I should have clarified that a copy/paste would not work.
#4
06/27/2011 (7:26 pm)
Ok so I did everything right, I followed post #11 and skipped those parts, added the console methods, then on the 2nd page, post #26, I added the 2nd bit of code below the console methods, and I added all the rest of the code in the original post for everything else. These are the errors I get when building:

---- Build started: Project: Creation Nation DLL, Configuration: Debug Win32 ------
1>  shapeBase.cpp
1>     Creating library ../../../game/Creation Nation_DEBUG.lib and object ../../../game/Creation Nation_DEBUG.exp
1>shapeBase.obj : error LNK2019: unresolved external symbol "public: void __thiscall ShapeBase::setGravity(float)" (?setGravity@ShapeBase@@QAEXM@Z) referenced in function "public: virtual void __thiscall ShapeBase::unpackUpdate(class NetConnection *,class BitStream *)" (?unpackUpdate@ShapeBase@@UAEXPAVNetConnection@@PAVBitStream@@@Z)
1>shapeBase.obj : error LNK2019: unresolved external symbol "public: float __thiscall ShapeBase::getGravity(void)" (?getGravity@ShapeBase@@QAEMXZ) referenced in function "float __cdecl cm_ShapeBase_getGravity(class ShapeBase *,int,char const * *)" (?cm_ShapeBase_getGravity@@YAMPAVShapeBase@@HPAPBD@Z)
1>../../../game/Creation Nation_DEBUG.dll : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 14 up-to-date, 0 skipped ==========
#5
06/29/2011 (8:32 pm)
Does anyone know what this means? I'm clueless.

Edit: Aha!! I figured it out. I totally left this part out:

F32 ShapeBase::getGravity()
{
return mGravity;
}

void ShapeBase::setGravity(F32 gravity)
{
mGravity = gravity;
if(!isGhost())
setMaskBits(GravityMask);
}

Do you ever get that sensation when you figure something out on your own, and you happen to feel smarter? It's great. :P
#6
06/30/2011 (8:39 pm)
Ok new problem:

When I run torque and load the blank mission, I get this error:
"String::String: string too short"
in engine/source/core/util/str.cpp(549)
String::String(const StringChar *str, SizeType len)
{
   PROFILE_SCOPE(String_char_len_constructor);
   if (str && *str && len!=0)
   {
      AssertFatal(len<=dStrlen(str), "String::String: string too short");
      _string = new ( len ) StringData( str );
   }
   else
      _string = StringData::Empty();
}

I have no idea what's going on :)


#7
07/02/2011 (4:05 am)
Quote:
"ShapeBase::_updateMeshVisibility() - Mesh visibility size mismatch!"
in engine/source/t3d/shapebase.cpp(4634),
void ShapeBase::_updateHiddenMeshes()
{
   if ( !mShapeInstance )
      return;

   // This may happen at some point in the future... lets
   // detect it so that it can be fixed at that time.
   AssertFatal( mMeshHidden.getSize() == mShapeInstance->mMeshObjects.size(),
      "ShapeBase::_updateMeshVisibility() - Mesh visibility size mismatch!" );

   for ( U32 i = 0; i < mMeshHidden.getSize(); i++ )
      setMeshHidden( i, mMeshHidden.test( i ) );
}

"TSShapeInstance::setMeshForceHidden - Invalid Index!"
in engine/source/ts/tsshapeinstance.cpp(525),
void TSShapeInstance::setMeshForceHidden( S32 meshIndex, bool hidden )
{
   AssertFatal( meshIndex > -1 && meshIndex < mMeshObjects.size(),
      "TSShapeInstance::setMeshForceHidden - Invalid index!" );
                  
   mMeshObjects[meshIndex].forceHidden = hidden;
}

and

"Vector<T>::operator[] - out of bounds array access!"
in engine/source/core/utilt/vector.h(666). (It's the works of the devil!)
template<class T> inline T& Vector<T>::operator[](U32 index)
{
   AssertFatal(index < mElementCount, "Vector<T>::operator[] - out of bounds array access!");
   return mArray[index];
}

and when I run the mission I built off of the blank mission (nothing but a black skybox and a sphere, plus the usual items like mission info.) I get this:

"Out of range read"
in engine/source/core/stream/bitstream.h(313).
inline bool BitStream::readFlag()
{
   if(bitNum > maxReadBitNum)
   {
      error = true;
      AssertFatal(false, "Out of range read");
      return false;
   }
   S32 mask = 1 << (bitNum & 0x7);
   bool ret = (*(dataPtr + (bitNum >> 3)) & mask) != 0;
   bitNum++;
   return ret;
}

...Probably something to do with
if (stream->readFlag()) { // GravityMask
         F32 gravity;
         stream->read(&gravity);
         setGravity(gravity);
      }
in shapeBase.cpp.
Here were the instructions:
Find the function:
------------
void ShapeBase::unpackUpdate(NetConnection *con, BitStream *stream)
{
}
------------

In that function, find:
------------
if (stream->readFlag()) { // NameMask
mNameTag = stream->readInt(NetStringTable::StringIdBitSize);
checkTagsNeeded = true;
}
------------

Either above or below it add:
------------
if (stream->readFlag()) { // GravityMask
F32 gravity;
stream->read(&gravity);
setGravity(gravity);
}
------------
The above issues were because of the GravityMask not being in correct order. After moving it around, the errors no longer appear. :)

String::String: string too short
is the only error that appears now, other than if I try to do anything in a mission other than walk around and shoot my gun (Which doesn't appear anymore...) I will crash. For example, going into world editor and clicking buttons will crash torque. Changing to freecam with alt+c will crash it. Also, there is now a square where the player spawns with a ton of jibberish inside of it.. i896.photobucket.com/albums/ac161/Pew446/jibb.png
#8
07/23/2011 (6:03 am)
Well very surprisingly, I fixed everything with my lack of C++ skills. Should I post a resource for Torque 3D? Also would I need Chris' permission to do that? (By the way Chris thanks a million for the resource :D)
#9
10/26/2011 (3:08 pm)
I am certain that others would enjoy the resource. It would add kudos to you, and usually when you update a resource you don't need permission but it is common courtesy to reference the old resource you based yours on. Glad you were able to get it to work.