"Adding new positions" enhancements
by Josh Moore · 09/02/2005 (5:25 pm) · 21 comments
This resource builds on the "Adding new positions" resource. So you'll have to have that installed before using this.
GetDamageLocation Fix
The fix for getDamageLocation breaks the percision of the original method. For my purposes, I only needed the general location on the player, since I'm only use it to check for headshots. So this new function will only return head, torso, and legs.
Anyways, replace your Player::getDamageLocation with this:
Keep player on water surface while swimming
For my game, I didn't want to allow players to beable to swim in whatever direction they wanted, so I put together this code to "lock" the players on the water surface while swimming.
Find this line of code
Crouch/Prone Bounding Box Fix
I realized that the current way of changing the boundng box size when going crouch/prone didn't keep the datablock defined bounding box dimensions, because they were hard coded. Just replace your Player::setPlayerPosition method with this(it also includes the onScaleChanged fix):
Potential Bug/Exploit Fix
To fix the pontential bug/exploit I just made the mSwimming variable public and did a simple bool check in the ConsoleMethod, like so:
Also, if you're using this resource you might want to add !mSwimming(and prone check if you don't have it :P) checks to the conform code.
GetDamageLocation Fix
The fix for getDamageLocation breaks the percision of the original method. For my purposes, I only needed the general location on the player, since I'm only use it to check for headshots. So this new function will only return head, torso, and legs.
Anyways, replace your Player::getDamageLocation with this:
void Player::getDamageLocation(const Point3F& in_rPos, const char *&out_rpVert, const char *&out_rpQuad)
{
Point3F newPoint;
mWorldToObj.mulP(in_rPos, &newPoint);
F32 zHeight;
if(mPlayerPosition == 3)
zHeight = mObjBox.max.y;
else
zHeight = mObjBox.max.z;
F32 zTorso = mDataBlock->boxTorsoPercentage;
F32 zHead = mDataBlock->boxHeadPercentage;
zTorso *= zHeight;
zHead *= zHeight;
if(mPlayerPosition == 3) {
if (newPoint.y <= zTorso)
out_rpVert = "legs";
else if (newPoint.y <= zHead)
out_rpVert = "torso";
else
out_rpVert = "head";
}
else {
if (newPoint.z <= zTorso)
out_rpVert = "legs";
else if (newPoint.z <= zHead)
out_rpVert = "torso";
else
out_rpVert = "head";
}
out_rpQuad = "center"; // default to "center", so we're not returning nothing
}Keep player on water surface while swimming
For my game, I didn't want to allow players to beable to swim in whatever direction they wanted, so I put together this code to "lock" the players on the water surface while swimming.
Find this line of code
acc.z = (-headRotation.x * (mDataBlock->swimForce / mMass) * 0.25f);and replace it with this:
// Added code to "lock" the player on the water surface - JM
RayInfo rInfo;
SimpleQueryList sql;
if (isServerObject())
gServerSceneGraph->getWaterObjectList(sql);
else
gClientSceneGraph->getWaterObjectList(sql);
F32 wtrSurface = 0;
Point3F currentPos = getPosition();
for (U32 i = 0; i < sql.mList.size(); i++)
{
WaterBlock* pBlock = dynamic_cast<WaterBlock*>(sql.mList[ i ]);
//if (pBlock && pBlock->isWater( pBlock->getLiquidType() )) {
if (pBlock) {
if (pBlock->isPointSubmergedSimple(currentPos))
wtrSurface = pBlock->getSurfaceHeight();
}
}
if(currentPos.z > wtrSurface)
wtrSurface = (currentPos.z - wtrSurface)*0.25;
else
wtrSurface = (wtrSurface - currentPos.z)*0.25;
acc.z = wtrSurface;
//----Crouch/Prone Bounding Box Fix
I realized that the current way of changing the boundng box size when going crouch/prone didn't keep the datablock defined bounding box dimensions, because they were hard coded. Just replace your Player::setPlayerPosition method with this(it also includes the onScaleChanged fix):
void Player::setPlayerPosition(S32 position)
{
F32 len_x, len_y, len_z;
if (position != mPlayerPosition) {
if (isProperlyAdded()) {
// Special case, this one bumps us up to the next position
if (position == 0) {
position = mPlayerPosition + 1;
if (position > 3)
position = 1;
}
switch (position) {
case 1: // Stand, walk
{
len_x = mDataBlock->boxSize.x;
len_y = mDataBlock->boxSize.y;
len_z = mDataBlock->boxSize.z;
break;
}
case 2: // Crouch, sit
{
len_x = mDataBlock->boxSize.x;
len_y = mDataBlock->boxSize.y;
len_z = mDataBlock->boxSize.z/2+0.15;// half the player height is too short
break;
}
case 3: // Crawl, prone
{
len_x = mDataBlock->boxSize.x;
len_y = mDataBlock->boxSize.z;
len_z = mDataBlock->boxSize.z/4;
break;
}
}
mObjBox.max.x = len_x * 0.5;
mObjBox.max.y = len_y * 0.5;
mObjBox.max.z = len_z;
mObjBox.min.x = -mObjBox.max.x;
mObjBox.min.y = -mObjBox.max.y;
mObjBox.min.z = 0;
onScaleChanged();
}
mPlayerPosition = position;
}
if (isServerObject())
setMaskBits(MoveMask);
}Potential Bug/Exploit Fix
To fix the pontential bug/exploit I just made the mSwimming variable public and did a simple bool check in the ConsoleMethod, like so:
[i]Player.h:[/i]
public:
bool mSwimming;
protected:
[i]Player.cc:[/i]
ConsoleMethod( Player, setPlayerPosition, void, 3, 3, "(1=stand, 2=crouch, 3=crawl)")
{
if(!object->mSwimming)
object->setPlayerPosition(dAtof(argv[2]));
}Also, if you're using this resource you might want to add !mSwimming(and prone check if you don't have it :P) checks to the conform code.
About the author
#2
09/02/2005 (9:20 pm)
Sweet.
#3
09/03/2005 (12:38 am)
Very nice!
#4
(EDIT)
Compiled cleanly but when I try to swim I just bounce on the water like a trampoline.
09/03/2005 (2:33 am)
This is awesome. Thank you for posting it.(EDIT)
Compiled cleanly but when I try to swim I just bounce on the water like a trampoline.
#5
@Midhir: Maybe you're swim speed is set to zero or something? I can swim just fine. The player does viborate a little bit, but that's due to "locking" him on the surface. :)'
EDIT: It seems the [ i ] in the water surface locking code was triggering italics on half the resource. You might want to check your code to make sure it's there in the water block lookup. Fixed the resource.
09/03/2005 (2:32 pm)
Thanks for the positive feedback! :D I posted another fix for a potential bug: setting the position through script while swimming.@Midhir: Maybe you're swim speed is set to zero or something? I can swim just fine. The player does viborate a little bit, but that's due to "locking" him on the surface. :)'
EDIT: It seems the [ i ] in the water surface locking code was triggering italics on half the resource. You might want to check your code to make sure it's there in the water block lookup. Fixed the resource.
#6
if I swim on the water that has a texture, it works great.
09/03/2005 (3:04 pm)
Just to let everyone the bouncing was only happening outside of the visible water square,if I swim on the water that has a texture, it works great.
#7
09/03/2005 (7:01 pm)
Very cool, I'll definately be using this very soon :)
#8
currently the camera position will not move in 1st person mode so when trying to crouch under anything you still see above the item
I have been able to get it to drop when crouching although all the crosshairs and aiming of weapons goes right out?
has any one got this fixed?
09/10/2005 (5:46 am)
I don't suppose you managed to sort the camera position out in 1st person mode when crouching or in prone position?currently the camera position will not move in 1st person mode so when trying to crouch under anything you still see above the item
I have been able to get it to drop when crouching although all the crosshairs and aiming of weapons goes right out?
has any one got this fixed?
#9
09/12/2005 (3:41 pm)
It works perfectly in my game. This is because we move the "eye" node in the crouch/prone animations.
#10
10/03/2005 (11:03 am)
Thanks Josh for this great resource!
#11
10/16/2005 (8:44 am)
Yeess ! Great resource!
#12
Did you ever fix the camera problem you were having? I'm having the same problem. We have the eye node moving with every thing else in the animation, so it should be working, but it isn't. If you or anyone else know of a way to fix it I'd appreciate the help, this needs to get fixed in the next couple days.
11/17/2005 (1:27 pm)
@ChrisDid you ever fix the camera problem you were having? I'm having the same problem. We have the eye node moving with every thing else in the animation, so it should be working, but it isn't. If you or anyone else know of a way to fix it I'd appreciate the help, this needs to get fixed in the next couple days.
#13
Do you have code for these checks for the less fortunate? ;)
02/16/2006 (10:58 pm)
Quote:Also, if you're using this resource you might want to add !mSwimming(and prone check if you don't have it :P) checks to the conform code.
Do you have code for these checks for the less fortunate? ;)
#14
02/18/2006 (6:51 am)
So the fix for camera position is to move the eye node in the animation itself?
#15
07/21/2006 (6:06 am)
Quote:Josh Moore:Can you explain a little bit how you did that? From the code, script or else? Thanks.
It works perfectly in my game. This is because we move the "eye" node in the crouch/prone animations.
#16
07/16/2007 (12:52 pm)
Quote:It works perfectly in my game. This is because we move the "eye" node in the crouch/prone animations.It appears to be set right in the animations I'm using (the orc) but the camera doesn't move when I go into crawl or crouch. Any idea why not?
#17
these do not simple have a acc variable of which' z component you may set to some value, this complicates things, and im not sure how to do this. maybe its in rigid or something, i really cant get it to work.
08/03/2007 (1:40 pm)
can anyone help me implement a water surface locking for wheeledvehicles or vehicles in general? these do not simple have a acc variable of which' z component you may set to some value, this complicates things, and im not sure how to do this. maybe its in rigid or something, i really cant get it to work.
#18
08/04/2007 (8:49 am)
deleted. (still could use some help please)?
#19
I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
09/11/2007 (5:49 pm)
Hello. I had some troubles using this resource in my project (see here for details).I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
#20
06/12/2008 (11:03 pm)
I tried using the bounding box fix in TGEA 1.03 and it doesn't seem to work. I made the boxes visible and they do not change at all. Anyone else have this problem? 
Associate Justin DuJardin
Default Studio Name