Underwater Swimming?
by JohnT · in Torque Game Engine · 01/05/2006 (5:04 pm) · 5 replies
Hello,
I am trying to implement a realistic swimming mod for the engine and hope someone can point me in the general area as to where I could rotate the player 90 degrees as he enters the water and then faces the direction (still in the horizontal position) as he is swimming.
I currently have the code working to make the player move in the direction he is aiming and have the appropriate animations but two major problems popped up.
1. Since I exported my swimroot pose with my player lying down, the arm animation still thinks he is standing and does not match 1st person view.
2. The player is always in the horizontal position as he is moving up and down through the water. Definately does not look like swimming!
Thanks for any help that can be offered.
I am trying to implement a realistic swimming mod for the engine and hope someone can point me in the general area as to where I could rotate the player 90 degrees as he enters the water and then faces the direction (still in the horizontal position) as he is swimming.
I currently have the code working to make the player move in the direction he is aiming and have the appropriate animations but two major problems popped up.
1. Since I exported my swimroot pose with my player lying down, the arm animation still thinks he is standing and does not match 1st person view.
2. The player is always in the horizontal position as he is moving up and down through the water. Definately does not look like swimming!
Thanks for any help that can be offered.
About the author
#2
Personally, I would add back in full rotation, much much easier than trying to "fake it" via rendering!
01/07/2006 (9:47 am)
Take a look at the pack/unpackUpdate() for the player class...rotation is clamped to only allow about the Z-Axis, which is why you are having to try to rotate the render image, not the player itself.Personally, I would add back in full rotation, much much easier than trying to "fake it" via rendering!
#3
Might give you an idea of how to do it.
01/07/2006 (10:54 am)
Might be worth looking at the "Adding new positions and moves; ie swim, crouch, crawl, prone" resource.Might give you an idea of how to do it.
#4
I have added the following back into the following methods and deleted where x and y were set to zero:
packUpdate():
stream->writeFloat(mRot.x / M_2PI, 7);
stream->writeFloat(mRot.y / M_2PI, 7);
unpackUpdate():
rot.x = stream->readFloat(7) * M_2PI;
rot.y = stream->readFloat(7) * M_2PI;
readPacketData():
stream->read(&rot.x);
stream->read(&rot.y);
writePacketData():
stream->write(mRot.x);
stream->write(mRot.y);
Also commented out in updateMove():
// constrain the range of mRot.x
if(mRot.x > 1.5706)
mRot.x = 1.5706;
else if(mRot.x < -1.5706)
mRot.x = -1.5706;
I can set z in updateMove and see the character rotate but if I set x or y nothing happens. Any idea what I missed?
Thanks!
01/07/2006 (11:32 am)
Thanks for the link. Actually, I have already included the Adding New Positions and Moves... resource. The problem is that in order to get the player to look correctly in the water I needed to create the swimroot animation with the character in the prone position. This causes the head movement and aiming to not be accurate when playing networked. I have added the following back into the following methods and deleted where x and y were set to zero:
packUpdate():
stream->writeFloat(mRot.x / M_2PI, 7);
stream->writeFloat(mRot.y / M_2PI, 7);
unpackUpdate():
rot.x = stream->readFloat(7) * M_2PI;
rot.y = stream->readFloat(7) * M_2PI;
readPacketData():
stream->read(&rot.x);
stream->read(&rot.y);
writePacketData():
stream->write(mRot.x);
stream->write(mRot.y);
Also commented out in updateMove():
// constrain the range of mRot.x
if(mRot.x > 1.5706)
mRot.x = 1.5706;
else if(mRot.x < -1.5706)
mRot.x = -1.5706;
I can set z in updateMove and see the character rotate but if I set x or y nothing happens. Any idea what I missed?
Thanks!
#5
I believe I found the last piece of code that was overriding mRot.x for a forward roll. When I have the player enter the water I execute mRot.x = PI; (I believe should flip player upside down, instead player stays oriented straight up and the controls for forward and backward are reversed???
01/07/2006 (3:04 pm)
Things are getting weird.I believe I found the last piece of code that was overriding mRot.x for a forward roll. When I have the player enter the water I execute mRot.x = PI; (I believe should flip player upside down, instead player stays oriented straight up and the controls for forward and backward are reversed???
Torque 3D Owner JohnT
I hope that someone has an easier way of doing this.