Game Development Community

Changing how mounted objects inherit movement

by Jonas · in Torque 3D Professional · 04/15/2014 (12:06 pm) · 7 replies

Hello, i have a question in regards to mounted objects and there movement inheritance from the object they are mounted to.

What im trying to achive is having the host object be able to rotate in one direction whilst a object that is mounted to said object wont rotate with it. The host objects movements are unreliable and not tied to specific input thus the rotation can not be calculated on a specific function call in script but needs to be checked every frame.

My first solution to this issue where to use onInterpolateTick(); script side, as the scope of the project is small enough to afford the preformance hit. However it seems to not really work out well for per-frame-pinpoint precision calculations and lags behind even though it is supposed to update every frame.

I could of course migrate over and work on a counter acting function within source instead but id much rather simply hit the problem head on and dissable movement inheritance to the player class(The player class being the objec that is mounted), as it is not needed in the type of project im working on and is just getting in the way.

My strength lies in Torque script for the most part although i do have exprience with C/C++ just not with T3D specificly so thats not really a issue i just need a pointer or two of where to start.

Advice or pointers in the general direction of where i should be looking on this would be greatly appreciated.

Best regards
Jonas

About the author

Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.


#1
04/17/2014 (5:30 pm)
So you mean you have some object mounted to another object that is rotating, and you want the mounted object to remain pointing in the same direction all the time? Mounting is handled in the C++ code, and every class that is mountable has to implement it in some way. For example, the Player class tried to find the transform of its parent mount's node:
void Player::setPosition(const Point3F& pos,const Point3F& rot)
{
   MatrixF mat;
   if (isMounted()) {
      // Use transform from mounted object
      MatrixF nmat,zrot;
      mMount.object->getMountTransform( mMount.node, mMount.xfm, &nmat );
      zrot.set(EulerF(0.0f, 0.0f, rot.z));
      mat.mul(nmat,zrot);
   }
   else {
      mat.set(EulerF(0.0f, 0.0f, rot.z));
      mat.setColumn(3,pos);
   }
   Parent::setTransform(mat);
   mRot = rot;

   if ( mPhysicsRep )
      mPhysicsRep->setTransform( mat );
}
But, on the other hand, Item doesn't do that at all, and ignores mounting. What class it the item you're trying to mount to another object? Chances are you'll have to check out the C++ implementation of setTransform and possibly getTransform and interpolateTick.
#2
04/18/2014 (6:47 am)
if (isMounted()) {
      // Use transform from mounted object
      MatrixF nmat,zrot;
      mMount.object->getMountTransform( mMount.node, mMount.xfm, &nmat );

	  //jlea: added these so we dont turn with the horse
	  //zrot.set(EulerF(0.0f, 0.0f, rot.z));
	  EulerF mountAngles = mMount.object->getTransform().toEuler();
	  zrot.set(EulerF(0.0f, 0.0f, rot.z - mountAngles.z));

	  mat.mul(nmat,zrot);
   }
   else {
      mat.set(EulerF(0.0f, 0.0f, rot.z));
      mat.setColumn(3,pos);
   }
   Parent::setTransform(mat);
   mRot = rot;

That's what I used.
#3
04/18/2014 (8:36 am)
@Daniel

thank you very much for your reply, the classes in question are the player class and the (wheeled)vehicle class. The vehicle class being the "host object" and the player the one that is mounted.
The mounted object won't neccesarily point in the same direction all the time as its direction is controlled by a seperate camera objects direction. Its just the mounted transform i seek to dissable.

@Aussie

Thank you very much for the code snippet, much appreciated!
#4
04/19/2014 (12:58 am)
Oke had some time to dig around in the player source today and using Aussie's modification on the ::setPosition and ::setRenderPosition the mounted player object is no longer following the vehicle rotation, i have to say its a very elegant solution to the problem.

However the camera is being very "jittery", it looks as if the camera object is trying to update with the vehicle transform but is then later corrected by the afformentioned changes. My first thought would be Player::updatePos needs to be modified as well, I'll have a look at it when time allows but until then any ideas why this is happening?

Details:
The camera im using at this point is standard setup, mounted to a players skeleton eye/cam node.
#5
05/02/2014 (6:03 am)
Alrighty managed to find what caused the camera stuttering issue. Wasent actually a issue in the camera class but a missmatch in SetPosition and SetRenderPosition. I assigned Transform to mountAngles in setRenderPosition and not RenderTransform.... Not sure how i missed that but oh well :).

Thank you and best regards
Jonas
#6
05/04/2014 (6:06 pm)
Hello again, got a follow up question to this one.

So disabling the inheritance from the mount node rot.z works great and that part of the class behaviour is as it should work. Now im looking at inheriting movement from another class objects camera transform in the rot.x axis but im having a hard time finding a good way to do that.

The class object i want to get my rot.x from is a seperate player class. This player is mounted to the same host object as the first player.

Best regards
Jonas
#7
05/07/2014 (4:57 am)
Oke i really need to stop programming for long periods of time, managed to get it working now.

Best regards
Jonas