How do you add swimming mechanics?

I thought this would be easy but then I realized that the controls for swimming would be completely different, and the camera controls would change, and the character’s collision box would change somehow, and the character would have to fall slower. I’m using character physics so the last bit is actually probably not going to be that hard. Speaking of which, is there anyway to calculate fall damage based on how far a player fell as well as how fast? Anyways, is all this possible without using states?


1 Like

I use a dynamic or rigid body, then control movement myself,

Collision with water-----and-----------Force 9.8*mass


You can use the same sensor to set a property to use to control animation states.

1 Like

Thanks but I’m kind of confused sorry.

collision with water -> negate gravity

collision with water---------and-------------force Z world 9.8*mass

Collision with water--------python (apply drag)

import bge

collision with water----and-------Property swimming=True
_______________—nand-----property swimming =False

set a property that can be accesses with logic in python scripts


WaterDemo.blend (444 KB)

Ok thanks. But what do you do with the collision box/(rotation?) and character model to make him horizontal?

Well, you can rotate it 90 degrees,

Or replace mesh, works on triangle meshes I think,

And the animation state should be able to be handled with a property you are setting with collision.

If swimming=False-------and--------action walk
Other conditions----------/

If swimming------and-----------action swimming
other conditions–/

Ok thanks :slight_smile:

For some reason my swimming property trigger is not working like normal …


import bge

if sens.positive:

Maybe if you add a way to check if he’s at a certain height in the water he stops going up?

just add a sensor, and have it detect the water, and parent to something, that does Position

and in player do

always------------and-----copy property touching

Oh cuz I wasn’t sure if that’s what you meant by it’s not working properly.

here you are sir

I ended up using a clock, so the player would not bounce between states to often


FullWaterDemo.blend (481 KB)

Lol nice! Thanks