Frictional Games Forum (read-only)
Underwater Player Physics - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Underwater Player Physics (/thread-19832.html)



Underwater Player Physics - AKZEL - 01-06-2013

Hey everyone, long time lurker - finally registered.
Before making my first custom story, I want to find out what's possible and what is not.

I'm gonna jump straight to business here.

Currently I'm trying to create a small underwater section, and I want the player to be "weightless", or at least experience less "gravity" when submerged. For this I have tried using AddPlayerBodyForce combined with a for-loop and a simple scriptbox. Whenever the player is inside the scriptbox called "UnderWaterArea", I want the player to be constantly but gently pushed upwards (Y+) by AddPlayerBodyForce. The "UnderWaterArea" is just a scriptbox that covers the whole "Liquidarea".

This is my script:
void OnStart()
{
AddEntityCollideCallback("Player", "UnderWaterArea", "UnderWaterScript", false, 1);
}

void UnderWaterScript(string &in asParent, string &in asChild, int alState)
{
if(alState == 1)
{
SetLocalVarInt("underwater", 1);
}
if(GetLocalVarInt("underwater") == 1)
{
for(int g=1;g<999;g++) AddTimer("grav"+g, 0.01, "Grav");
}
}
void Grav(string &in asTimer)
{
AddPlayerBodyForce(0, 58, 0, false); //I have tried tweaking this, any lower and the player falls straight down to the bottom.
}

And this is how said script not works:
https://vimeo.com/56848115

Questions:
1. Is this effect even possible to achieve, or should I just leave it? I have searched the interwebs for this specific effect but haven't found anything...
2. How come the game freezes slightly every time the player collides with the UnderWaterArea?
3. How come the player eventually falls down to the bottom, even though he's still in the UnderWaterArea, thus should be affected by AddPlayerForce?

Hope I haven't made a total fool out of myself, first impression and so on... Wink
Cheers!


RE: Underwater Player Physics - Adrianis - 01-07-2013

You can make it so that the player descends more slowly and can jump higher by applying a +Y force to the player body as you have done, though that value is so low I'm surprised you notice any difference, I was messing around with a similar effect the other day using about 1000 or more for the Y value.

It's likely freezing slightly because the script is not exiting the FOR loop untill all 999 cycles have finished, then running all those timers in a very short space of time. The player will eventually fall all the way down because there isnt enough force to keep her 'afloat', and also because you're only making the grav function loop 999 times within an extremely small space of time

Try it more like this...

void OnStart()
{
AddEntityCollideCallback("Player", "UnderWaterArea", "UnderWaterScript", false, 1);
}

void UnderWaterScript(string &in asParent, string &in asChild, int alState)
{
// any other effects you may want, splashing sound perhaps?
Grav("");
}

void Grav(string &in asTimer)
{
AddTimer("GravTimer", 0.01, "Grav");
AddPlayerBodyForce(0, 1000, 0, false); // tweek to get the right value
}

This way, the Grav function will keep looping every 0.01 secs, since every time it runs it adds a new timer to activate itself. If you want to stop the effect, you'll need to use another area callback or similar using the RemoveTimer("GravTimer"), which should cut off the loop

Hope that helps. This script is entirely untested as I am at work, I accept no liability for grievous damage and/or explosive decompression caused or incurred whilst using the above script

EDIT: Just watched the video (I know, replying without watching how rude), I think the reason its pausing and the reason why such a low force value is throwing the player up is the same, your for loop is making 999 timers all fire at the same time, which means the total amount of force being applied is absolutely huge, you might find 0.01s to be too quick for a loop speed in my script (the force may apply exponentially)


RE: Underwater Player Physics - Rapture - 01-07-2013

I can help you out later when I get some time, but here is a link to a old forgotten CS that made a decent underwater effect, to help you out for now.

http://www.frictionalgames.com/forum/thread-9563.html?highlight=Underwater

Their is a link for a youtube video inside it, but here it is.





Edit: Your effectively trying to call the script a 1000 times in 10 seconds, that is why the game is lagging.


RE: Underwater Player Physics - str4wberrypanic - 01-07-2013

(01-07-2013, 05:45 PM)Rapture Wrote: I can help you out later when I get some time, but here is a link to a old forgotten CS that made a decent underwater effect, to help you out for now.

http://www.frictionalgames.com/forum/thread-9563.html?highlight=Underwater

Their is a link for a youtube video inside it, but here it is.





Edit: Your effectively trying to call the script a 1000 times in 10 seconds, that is why the game is lagging.
How can i make this thing underwater?