Friction in a physical zone
by Gary Preston · in Torque Game Engine · 09/06/2004 (1:52 pm) · 5 replies
Hi,
I'm a beginner to this, so please bear with me if it's an obvious answer.
I've done a little digging in the forums and resources to try to find a way to make a zero-G environment. The first attempt I've made, isn't too bad. I've used the PhysicalZone object and set the gravity modifier to 0.
Now when a player enters this area they float :) However, over time they slow down to a stop. So I need to remove the air friction that is been applied to the player.
From what I can gather, I'll need to modify the player.cc code to use a mDrag value of 0. however I only want this to apply whilst the player is within the physicalZone.
So, assuming setting Drag to 0 will do what I want, how can I go about linking a field "DragMod" of the physicalzone set via the in game mission editor, to a variable that I can test for in the player UpdateMove?
(like how the mGravityMod is linked to the physicalZones gravity field. I've tried to trace this, but currently I'm a bit overwealmed... so any pointers that might speed this up are appreciated)
Also, I'm not clear as to how the player class actually knows that a player is within the physicalmodifier and to apply the dragmod. Can anyone clarify how the mGravityMod is set to the value of the physicalZone that a player may enter?
Cheers.
I'm a beginner to this, so please bear with me if it's an obvious answer.
I've done a little digging in the forums and resources to try to find a way to make a zero-G environment. The first attempt I've made, isn't too bad. I've used the PhysicalZone object and set the gravity modifier to 0.
Now when a player enters this area they float :) However, over time they slow down to a stop. So I need to remove the air friction that is been applied to the player.
From what I can gather, I'll need to modify the player.cc code to use a mDrag value of 0. however I only want this to apply whilst the player is within the physicalZone.
So, assuming setting Drag to 0 will do what I want, how can I go about linking a field "DragMod" of the physicalzone set via the in game mission editor, to a variable that I can test for in the player UpdateMove?
(like how the mGravityMod is linked to the physicalZones gravity field. I've tried to trace this, but currently I'm a bit overwealmed... so any pointers that might speed this up are appreciated)
Also, I'm not clear as to how the player class actually knows that a player is within the physicalmodifier and to apply the dragmod. Can anyone clarify how the mGravityMod is set to the value of the physicalZone that a player may enter?
Cheers.
#2
// Take into account any physical zones...
for (U32 j = 0; j < physZoneCollisionList.count; j++) {
AssertFatal(dynamic_cast(physZoneCollisionList.collision[j].object), "Bad phys zone!");
PhysicalZone* pZone = (PhysicalZone*)physZoneCollisionList.collision[j].object;
if (pZone->isActive())
mVelocity *= pZone->getVelocityMod();
}
a pZone has a getVelocityMod(); and a getForce();
You could potentially take the x,y or z component in getForce() and use that as your friction modifier.
-s
09/06/2004 (4:07 pm)
In player.cc somewhere in updatePos it checks to see if its in a physical zone. I dont think the PZs have a built-in drag/friction... // Take into account any physical zones...
for (U32 j = 0; j < physZoneCollisionList.count; j++) {
AssertFatal(dynamic_cast
PhysicalZone* pZone = (PhysicalZone*)physZoneCollisionList.collision[j].object;
if (pZone->isActive())
mVelocity *= pZone->getVelocityMod();
}
a pZone has a getVelocityMod(); and a getForce();
You could potentially take the x,y or z component in getForce() and use that as your friction modifier.
-s
#3
Cheers for the pointers.
09/08/2004 (3:35 am)
Edit: Done :) I updated the physicalZone to have a new field "DragMod" which is applied to mDrag. Although it was a simple change in the end, I've learnt a little more about how torque fits together.Cheers for the pointers.
#5
The change as far as I remember was pretty simple, if you look at how mGravityMod is handled in the source for physicalZones, you can use this as a basis for exposing a new variable mDragMod. Basically you will need to add it into initPersistFields so that the mission editor picks up on it as well as adding appropriate read/write calls to pack/unpackUpdate. Also add an accessor function getDragMod() that returns mDragMod.
Next add a new variable to ShapeBase called mDragMod and initialise it to 1.0 in the constructor so that by default it will have no effect on drag. In ShapeBase fina a function called updateContainer. This finds any objects within the shapes world box which includes physical zones. It is here that the you want to reset mDragMod to 1.0.
This method will call the physicalZoneFind method for each physical zone the shape is within, which is where you can update the mDragMod to account for the drag mod of the current zone. E.G
mDragMod *= pz->getDragMod();
Finally you just need to find where mDrag is used in player.cc and multiply it by mDragMod.
I'm pretty sure that is all I changed, however this was a few years back so I can't be certain I havn't missed anything out. In fact I had to check shapeBase to remember the function names used above :) If you have any problems though, let me know and I'll try to help.
03/13/2006 (4:17 pm)
Rawles: If I still had the code I'd post it for you, but I didn't keep most of my early experiments with TGE since they served no purpose other than to learn more about TGE.The change as far as I remember was pretty simple, if you look at how mGravityMod is handled in the source for physicalZones, you can use this as a basis for exposing a new variable mDragMod. Basically you will need to add it into initPersistFields so that the mission editor picks up on it as well as adding appropriate read/write calls to pack/unpackUpdate. Also add an accessor function getDragMod() that returns mDragMod.
Next add a new variable to ShapeBase called mDragMod and initialise it to 1.0 in the constructor so that by default it will have no effect on drag. In ShapeBase fina a function called updateContainer. This finds any objects within the shapes world box which includes physical zones. It is here that the you want to reset mDragMod to 1.0.
This method will call the physicalZoneFind method for each physical zone the shape is within, which is where you can update the mDragMod to account for the drag mod of the current zone. E.G
mDragMod *= pz->getDragMod();
Finally you just need to find where mDrag is used in player.cc and multiply it by mDragMod.
I'm pretty sure that is all I changed, however this was a few years back so I can't be certain I havn't missed anything out. In fact I had to check shapeBase to remember the function names used above :) If you have any problems though, let me know and I'll try to help.
Torque Owner Josh Moore