Mount rotation offset
by Fenrir Wolf · in Torque Game Builder · 06/08/2005 (1:07 am) · 12 replies
Okay, let's imagine you want to mount one object to another and have it track the rotation. Easy enough to do.
But let's say that you want to offset that mount's rotation by a certain amount. ie: A turret is attached to a ship, but you don't want it to face in the same direction as the ship but 45 degrees offset. As far as I can tell, this is impossible in T2D currently -- even with multiple mounts. (As soon as you set it to track rotation, that object's rotation is "overwritten" by the parent.)
I propose a mount rotation offset. This will let you maintain an independant angle for the mounted object, while also have it track the parent's rotation.
Actually, I've done more than just proposed it, I've implemented it in my T2D copy. For example, in fxSceneObject2D::updateMount(), I've changed this:
I set mMountOffsetRotation using the usual ConsoleFunction/public method combo. ie:
And with a slight mod to the constructor (fxSceneObject2D::fxSceneObject2D()):
And finally, add "F32 mMountOffsetRotation" to the public declaration of fxSceneObject2D.
This isn't a drop-in implementation, as it currently doesn't write this value to the file stream (and therefore breaks the state save/load capacity, plus future networking), but that's fairly easy to add if you need it.
Anyway, I needed this for my project and thought I'd share it as a future feature for T2D. :)
But let's say that you want to offset that mount's rotation by a certain amount. ie: A turret is attached to a ship, but you don't want it to face in the same direction as the ship but 45 degrees offset. As far as I can tell, this is impossible in T2D currently -- even with multiple mounts. (As soon as you set it to track rotation, that object's rotation is "overwritten" by the parent.)
I propose a mount rotation offset. This will let you maintain an independant angle for the mounted object, while also have it track the parent's rotation.
Actually, I've done more than just proposed it, I've implemented it in my T2D copy. For example, in fxSceneObject2D::updateMount(), I've changed this:
if ( mMountTrackRotation ) setRotation( -mpMountedTo->getRotation() + mMountOffsetRotation ); // DAVIDG
I set mMountOffsetRotation using the usual ConsoleFunction/public method combo. ie:
//-----------------------------------------------------------------------------
// Set Mount Offset Rotation.
//-----------------------------------------------------------------------------
// DAVIDG
ConsoleMethod(fxSceneObject2D, setMountOffsetRotation, void, 3, 3, "(rotation) - Sets the mount objects rotation.")
{
// Set Rotation.
object->setMountOffsetRotation( dAtof(argv[2]) );
// Update Container Configuration.
object->updateContainerConfig();
}
// Set Rotation.
// DAVIDG
void fxSceneObject2D::setMountOffsetRotation( F32 rotation )
{
// Set Position.
mMountOffsetRotation = rotation;
}And with a slight mod to the constructor (fxSceneObject2D::fxSceneObject2D()):
mMountOffsetRotation = 0.0 ; // DAVIDG
And finally, add "F32 mMountOffsetRotation" to the public declaration of fxSceneObject2D.
This isn't a drop-in implementation, as it currently doesn't write this value to the file stream (and therefore breaks the state save/load capacity, plus future networking), but that's fairly easy to add if you need it.
Anyway, I needed this for my project and thought I'd share it as a future feature for T2D. :)
#2
For example, if you have an "anchor" object which has several other objects mounted to it, and you want those objects to remain in their positions but be mounted to the anchor object, you have to translate the coordinates manually to position them correctly. Hmm. Like this:
Also, it would be nice if we could optionally have "linear" mount force. In some cases, you don't want objects to slowly accelerate and decelerate. Specifying the kind of force to apply would be a nice addition.
06/08/2005 (4:17 pm)
Related to mount offsets (or possibly very similar) is a way to specify a mount position that isn't relative to the object's local space. I created a function to translate local coordinates to world coordinates, but of course it would be nice if the engine was able to do this, too.For example, if you have an "anchor" object which has several other objects mounted to it, and you want those objects to remain in their positions but be mounted to the anchor object, you have to translate the coordinates manually to position them correctly. Hmm. Like this:
//-----------------------------------------------------------------------------
// Translate local coordinates into world coordinates.
//-----------------------------------------------------------------------------
function localToWorld( %localUnits, %objSize )
{
return %localUnits * (%objSize / 2);
}
//-----------------------------------------------------------------------------
// Translate world coordinates into local coordinates.
//-----------------------------------------------------------------------------
function worldToLocal( %worldUnits, %objSize )
{
return %worldUnits / (%objSize / 2);
}Also, it would be nice if we could optionally have "linear" mount force. In some cases, you don't want objects to slowly accelerate and decelerate. Specifying the kind of force to apply would be a nice addition.
#3
Jason: Hmm, good point, those are two handy functions. I'm not sure how that could be elegantly handled though, other than to use two helper functions such as what you've mentioned. Either that, or adding yet another flag to the mount command to tell it the incoming is world coords instead of local space. (Ugly!)
So you'd rather have the choice between toggling damping? Maybe the mount could use the mounted object's damping value to determine its response. (With zero meaning linear movement.) Hmm.
06/08/2005 (9:33 pm)
Melv: Good point, that would break backwards compatibility without the appropriate planning. :) Oh yeah, I forgot I had already mentioned this on my wish-list, thanks for the reminder. Heck I've been away for so long, I wasn't sure if this had been addressed anyway and just didn't know the command for it. ;)Jason: Hmm, good point, those are two handy functions. I'm not sure how that could be elegantly handled though, other than to use two helper functions such as what you've mentioned. Either that, or adding yet another flag to the mount command to tell it the incoming is world coords instead of local space. (Ugly!)
So you'd rather have the choice between toggling damping? Maybe the mount could use the mounted object's damping value to determine its response. (With zero meaning linear movement.) Hmm.
#4
...if that makes any sense. :)
06/09/2005 (9:59 am)
One reason for linear mount force would be when you use mounting to move an object between 2 points, but you don't want the acceleration/deceleration between points (ie, waypoints). Linear force would make the transition between points "fluid" instead of "stop/start" at each point....if that makes any sense. :)
#5
I am loving T2D :)
regards
- Jesse
06/29/2005 (7:59 am)
Id like to be able to change the mount offset on the fly or have an inverse of the chase camera mode. What im trying to accomplish is opening up more of the screen ahead of my object relative to the object speed. I am loving T2D :)
regards
- Jesse
#6
06/29/2005 (9:18 am)
So as your moving forward your wanting the camera to begin moving away from centering on your object and moving the object moreso to the edge of the camera giving more viewable distance ahead? (lol I'm a bit tired so correct me if I have this wrong)
#7
the camera shifts foreward giving a more viewable distance ahead.
06/29/2005 (9:28 am)
That is correct. the camera shifts foreward giving a more viewable distance ahead.
#8
06/29/2005 (9:30 am)
Hmm, you could mount the camera to a fxSceneObject2D that follows ahead of your player (or main object) with that behavior, would probably base the lead on whatever velocity the object is moving in and what direction
#9
If I get the players angle and then calculate a point ahead or behind based on a speed offset. Essentially it would be the inverse of the way the current chase mode works I imagine.
Just have to figure out the math and I think it'll work.
06/29/2005 (9:45 am)
Good idea.. If I get the players angle and then calculate a point ahead or behind based on a speed offset. Essentially it would be the inverse of the way the current chase mode works I imagine.
Just have to figure out the math and I think it'll work.
#10
06/29/2005 (10:06 am)
Exactly what I was thinking :) if you get the math right it should slow down and meet right up with the player as you slow down.
#11
06/29/2005 (11:20 am)
In addition id like to add a chase to the turn arc so more of the turning radius is viewable and the transistion is smooth. Experimenting with driving a vehicle and just setting the Y offset forward makes turning fairly jerky since the tile map has to adjust for the offset with the rotation.
#12
09/23/2005 (9:16 pm)
@David : I ran into a snag with my project and your ressource proved to be exactly what I was looking for. Thank you so much. I know T2d 1.1 is coming...but in the mean-time, I'll work with what I have.
Employee Melv May
The next release will be a major one. :)
- Melv.