Jump to content

Can I automatically simulate swimming when I'm under water?


Innula Zenovka
 Share

You are about to reply to a thread that has been inactive for 4772 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Someone's asked me to make a device that has them automagically swimming when they're under water, and as far as I know -- I would be delighted to be told I'm mistaken -- there's no way with either the standard viewer or RLV for a script to turn on flying.

So, I can find out if I'm under water or not, using llWater.   If I am, I can over-ride the standard walk animation with a swimming one (and "stand" with treading water, I guess).   But I'm a bit at a loss how best to make myself float or swim.

My initial thought is that I'd do something with llSetForce to make myself weightless (that seems more straightforward in a hud than trying to use llSetBuoyancy, though I may be mistaken), and then use control events to "swim" in the appropriate direction (or up or down, of course, by altering the force parameters.   

Is this a sensible way to proceed or am I off-beam?

Link to comment
Share on other sites

 


Innula Zenovka wrote:

So, I can find out if I'm under water or not, using llWater.   If I am, I can over-ride the standard walk animation with a swimming one (and "stand" with treading water, I guess).   But I'm a bit at a loss how best to make myself float or swim.

I have used one for years. You are on the right track. When under water I use a swim animation for 'walk'. When standing I just stand on the bottom. When flying I substitute the fly animation with the swim animation. Above water everything is normal walk, stand and fly.
The one I use doesn't float on the surface, but it changes nicely from walk to swim when I enter water and back when I get up on dry land.
In fly mode It changes smoothly from swimming to flying when flying out of the water and back when I submerge.
The AO works for Linden waters only, pools at higher levels doesn't trigger a swim.

 

Link to comment
Share on other sites

My problem is, though, Darkie -- or at least I think it is -- that if I simply replace the walk anim with the swim anim when I'm under water, I don't see how I can swim down towards the seabed or back up towards the surface.   Won't I just carry on at the same depth until I encounter an obstacle?

My ZHAO switches to swimming anims if I'm flying and under water, and I can see how it does that,  but what I've been asked to make is something that obviates the need to switch to flying when you find yourself submerged.

Link to comment
Share on other sites

I did this a really long time ago so I've forgotten the details, but I recall using llSetBuoyancy in combination with some other physics on the HUD, llTakeControls, and an AO function, and it mostly worked fine.  Pretty sure that's how Siggy's "Swimmer" and similar work.  I can go back and dredge up details if you get stuck.

I seem to recall having trouble at the transition coming out of the water.  I remember some swimmers would fly off at great velocity.  Not sure if I ever got 'round to fixing that because, hey, swimming and suborbital flight -- what could be better?

TBH, mine was less an exercise in swimming than in sharing animations.  Back in those more frugal days, the cost of a Swimmer for everybody who might want to swim seemed completely implausible, so I scripted the physics and made the prim water be both an animation server and the surface height setter (no pricey Linden water land for us!).  Then I ripped the guts out of one copy of the Swimmer and every other swimming AO I could find at the time and stuffed the anims into the water server.

Link to comment
Share on other sites

I got the impression OP realized that AO's could easily swap animations for above/below water, but was looking for a way to force "fly" when walking was detected.... and assumed (AFAIK) correctly, that there aren't any feasible method to do that (force up would trigger jumping or falling)

if someone could figure a way to trigger avatar intersect with an object/ground at will then it might be possible (as both of those often result in flying, and I'm assuming you could use exact value to trigger it each time consistently)

Link to comment
Share on other sites

Maybe I'm not seeing some obvious complexity, but couldn't you just script an object with llWater to detect whether it is above or below the sim's water table? Trigger a fast timer event  when you sit on the object, then

if (llWater(ZERO_VECTOR) < 0.0) {llStartAnumation("I'm_swimming");}

else {llStartAnimation("I'm flying");}

Use a control event to handle movement of the object.  If you're trying to swim in a pool or if you want to swim under water, you'll need to feed it an offset vector, but that shouldn't be all that hard.  Or am I missing something?

 

Link to comment
Share on other sites

What I've been asked to make, though, is an attachment, so the person wearing it will start swimming automatically as soon as he or she is in Linden water.   So rezzing an object and sitting on it, while a good solution in general, won't meet the requirements in this case.

I have pointed out that it would be far simpler to use an AO that knows to play a swimming, rather than flying, animation when you're "flying" underwater, but apparently that's very much second-best as far as one particular RP community is concerned.  

Link to comment
Share on other sites


Innula Zenovka wrote:

What I've been asked to make, though,
is an attachment
, so the person wearing it will start swimming automatically as soon as he or she is in Linden water.

I have pointed out that it would be
far simpler to use an AO
that knows to play a swimming, rather than flying, animation when you're "flying" underwater, but apparently that's very much second-best as far as one particular RP community is concerned.  

An AO is a script in an attachment, so why can't your attachment work like an AO?:womansurprised:

 

Link to comment
Share on other sites

Well, I dug around in my ancient alt's inventory and found the scripts I was using.  Tried to tinker with their physics parameters to behave sensibly on current Havoc -- these were Havoc 1 and pre-Mono scripts that I haven't looked at in years.  The result of my tinkering is far from satisfactory at this point (it keeps thinking that I'm already out of the pool whenever I try to tread water, among other maladjustments), but the basic scheme detects when the agent is in the water and sets buoyancy, and uses llApplyImpulse to gradually float to the surface and for propulsion and damping in any direction, including diving, in response to control inputs (which it does not pass through to regular avatar motion, except rotation).  It does not use a standard AO script in that it doesn't pay any attention to the agent's animation state, but rather only its velocity.

I'm remembering now that the problem with just using an AO for swimming is that it just doesn't feel anything like swimming.  For one thing, it moves way, way too fast and doesn't bob to the surface when controls aren't applied.  That's why Siggy and others have whole businesses in swimming HUDs, swimballs, etc.

Link to comment
Share on other sites

Thanks so much for dropping a copy on me, Dora.  That's clarified a lot of things for me, and I hadn't thought things through properly.  

Of course, when I want to swim upwards, I'm going to have to hit PgUp, which will start me flying if I'm not flying already.  Silly me!

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4772 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...