Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Underwater Player Physics
AKZEL Offline
Junior Member

Posts: 3
Threads: 3
Joined: Jan 2013
Reputation: 0
#1
Lightbulb  Underwater Player Physics

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!
(This post was last modified: 01-06-2013, 12:53 PM by AKZEL.)
01-06-2013, 12:50 PM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#2
RE: Underwater Player Physics

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)
(This post was last modified: 01-07-2013, 04:38 PM by Adrianis.)
01-07-2013, 04:33 PM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#3
RE: Underwater Player Physics

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/thr...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.
(This post was last modified: 01-07-2013, 05:56 PM by Rapture.)
01-07-2013, 05:45 PM
Find
str4wberrypanic Offline
Member

Posts: 241
Threads: 24
Joined: Jul 2012
Reputation: 8
#4
RE: Underwater Player Physics

(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/thr...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?

01-07-2013, 06:27 PM
Find




Users browsing this thread: 1 Guest(s)