Game Development Community

Addfing swimming

by AndrewOsborne · in Technical Issues · 02/27/2003 (3:59 am) · 3 replies

How would one go about writing code to make the player swim, like in halflife or q3a

#1
02/27/2003 (7:45 am)
add a swim animation and detect if they are covered by water by a certain percentage and then force that animation to play. You would also have to do something about reducing gravity inside the waterblocks more and some other tweaky stuff, it goes from "simple" to "complicated" really fast.

I know this can be done on the C++, there should be a way to do it via scripting also.
#2
03/10/2003 (2:05 pm)
To change a player's gravity (runspeed, etc.) either requires the Python modifications, or additional code changes. I believe there was a codesnippit on how to do it, at one point in time.

You would probably also want to change the action map (most games alter the controls some in the water), and you might want to include animations for transitioning from walking to swimming and from swimming to walking. Traditionally, the swimming animation has been triggered at about chest deep in the water, to help hide the transition (if the character swims vertically, you may be able to get away without a transition).

Theoretically, you would lower run speed, and set gravity low (or to zero) to get it to feel right. You have to have some drag. This would also require some changes in the engine, as it is hard-coded to play animations in response to certain movement thresholds being reached, and you wouldn't want that. You might be able to do it without changing the engine, but I'd be concerned it could get into the wrong animation.
#3
03/12/2003 (4:46 am)
Sorry but gravity wouldnt help, becaue its just like a big jump, i need morelike a constant godmaode for underwater where you can move all directions, swimming requires constant force able to be assigned which you cant do while jumping.