# Swimming

Simple Question- How do I make my character swim?

Well, I would suggest making a demo scene where you pretend that you are always underwater and then program the way it is controlled and the animation. Then implement it into a game and have it only work when you are under water, I guess that is the tricky part.

I’m working on the same thing; Make the water a large trigger with correct water physics, then put your character into it. The character should be controlled by physics, not by a character controller, so that things like water flow have an effect on the player. Then simply add a force to your character into the direction you want it to swim, the water physics will do the rest.
(ps: The water should turn on/off an isSwimming boolean) to enable/disable swimming)

Okay, I just finished my water physics script, maybe you’re interested…
(ps: I know, it’s not a correct mathematical approuch, but more some pseudo-physical solution to this problem…)

``````var density = 0.999;
var airDens = 0.013;
// In something like gram per cubic centimeter
var flux : Vector3;
var gravity = 9.81;
var surfaceHeight = 0.0;
var damper = 1.0;
var thickness = 0.5;
var normDrag = 0.0;
var waterDrag = 0.99;

function OnTriggerEnter (other : Collider) {
}

function OnTriggerStay (other : Collider) {
if (other.GetComponent(Rigidbody)) {
var size = other.bounds.size;
var volume : float = size.x*size.y*size.z;
var dens = other.rigidbody.mass/volume;
other.rigidbody.AddForce(transform.up * ((density-dens) * (surfaceHeight - other.transform.position.y) * damper / thickness - other.rigidbody.velocity.y/gravity) + flux/dens);
other.rigidbody.drag = waterDrag + (surfaceHeight - other.transform.position.y) * (waterDrag/gravity) + (0 - other.rigidbody.velocity.y) * (waterDrag/damper);
var colliders : Collider[] = Physics.OverlapSphere (other.transform.position, volume/(damper/dens*2));
for (var effect in colliders) {
if (effect.rigidbody  effect != other  effect.rigidbody.drag != 0.0) {
effect.rigidbody.AddForce(other.rigidbody.velocity * (damper/thickness) / effect.rigidbody.mass * Vector3.Normalize(other.rigidbody.velocity).magnitude * airDens);
var angl = (other.rigidbody.angularVelocity+other.rigidbody.velocity)/2;
}
}
}
}

function OnTriggerExit (obj : Collider) {