Frictional Games Forum (read-only)
Gravity - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: SOMA (https://www.frictionalgames.com/forum/forum-55.html)
+--- Forum: User created content (https://www.frictionalgames.com/forum/forum-79.html)
+---- Forum: Technical Support (https://www.frictionalgames.com/forum/forum-80.html)
+---- Thread: Gravity (/thread-52072.html)



Gravity - Venom Fox - 08-03-2016

Hey, so I wanted to create a room that has low gravity, I used this for it:

Player_SetGravity(-0.45f);

Now I don't know if that's the best code to use if I want to get low gravity, but it works (kind of) except for one little issue where the character is slowly moving to some direction, but it's not the main problem.

The main problem is that I can't set the gravity back to normal. I've tried so many things, i.e Player_SetGravity(1.0f); or Player_SetGravity(-1.0f); or even Player_ChangeStateToNormal();

None of them works, any ideas...? :S


RE: Gravity - Darkfire - 08-03-2016

Maybe Player_SetGravity(0.0f); ?

Here's the script I used for that effect:
Spoiler below!

PHP Code:
void UnderWater(string &in asParentstring &in asChildint alState////this function was executed when entering an area, making the player float in low gravity
{
    
SetLanternActive(falsetrue);
    
SetLanternDisabled(true);
    
SetPlayerLookSpeedMul(0.85f);
    
SetPlayerRunSpeedMul(0.8f);
    
SetPlayerMoveSpeedMul(0.7f);
    
AddTimer("slow"0.01f"SlowJump");
}

void SlowJump(string &in asTimer)
{
    if(
asTimer == "slow")
    {
        
AddTimer("slow"0.01f"SlowJump"); ////this is the proper part that gives low gravity - it has to be a timer on a loop
        
if(GetPlayerYSpeed() > 0.01f)
        {
            
AddPlayerBodyForce(06000false);
        }
    }
    if(
asTimer == "normal")
    {
        
RemoveTimer("slow");
    }
    
}

void NoWater(string &in asParentstring &in asChildint alState/////andd this was executed when leaving the area, which resulted in normal gravity
{
    
SetLanternDisabled(false);
    
SetPlayerLookSpeedMul(1.0f);
    
SetPlayerRunSpeedMul(1.0f);
    
SetPlayerMoveSpeedMul(1.0f);
    
AddTimer("normal"0.01f"SlowJump");





RE: Gravity - Venom Fox - 08-03-2016

(08-03-2016, 03:20 PM)Darkfire Wrote: Maybe Player_SetGravity(0.0f); ?

Here's the script I used for that effect:
Spoiler below!

PHP Code:
void UnderWater(string &in asParentstring &in asChildint alState////this function was executed when entering an area, making the player float in low gravity
{
    
SetLanternActive(falsetrue);
    
SetLanternDisabled(true);
    
SetPlayerLookSpeedMul(0.85f);
    
SetPlayerRunSpeedMul(0.8f);
    
SetPlayerMoveSpeedMul(0.7f);
    
AddTimer("slow"0.01f"SlowJump");
}

void SlowJump(string &in asTimer)
{
    if(
asTimer == "slow")
    {
        
AddTimer("slow"0.01f"SlowJump"); ////this is the proper part that gives low gravity - it has to be a timer on a loop
        
if(GetPlayerYSpeed() > 0.01f)
        {
            
AddPlayerBodyForce(06000false);
        }
    }
    if(
asTimer == "normal")
    {
        
RemoveTimer("slow");
    }
    
}

void NoWater(string &in asParentstring &in asChildint alState/////andd this was executed when leaving the area, which resulted in normal gravity
{
    
SetLanternDisabled(false);
    
SetPlayerLookSpeedMul(1.0f);
    
SetPlayerRunSpeedMul(1.0f);
    
SetPlayerMoveSpeedMul(1.0f);
    
AddTimer("normal"0.01f"SlowJump");



Nah, won't work.. :/


RE: Gravity - Darkfire - 08-03-2016

So if anything else fails, try my script. It works and looks quite good.


RE: Gravity - Romulator - 08-03-2016

(08-03-2016, 03:05 PM)Venom Fox Wrote: Hey, so I wanted to create a room that has low gravity, I used this for it:

Player_SetGravity(-0.45f);

Now I don't know if that's the best code to use if I want to get low gravity, but it works (kind of) except for one little issue where the character is slowly moving to some direction, but it's not the main problem.

The main problem is that I can't set the gravity back to normal. I've tried so many things, i.e Player_SetGravity(1.0f); or Player_SetGravity(-1.0f); or even Player_ChangeStateToNormal();

None of them works, any ideas...? :S

Have you got any other events occurring when Gravity resets so you can confirm the script is actually working? If you can make use of Debug Messages, I really recommend it.

(08-03-2016, 03:53 PM)Darkfire Wrote: So if anything else fails, try my script. It works and looks quite good.

And while it does work, we're working with SOMA here, not Amnesia Wink


RE: Gravity - Venom Fox - 08-03-2016

(08-03-2016, 04:59 PM)Romulator Wrote:
(08-03-2016, 03:05 PM)Venom Fox Wrote: Hey, so I wanted to create a room that has low gravity, I used this for it:

Player_SetGravity(-0.45f);

Now I don't know if that's the best code to use if I want to get low gravity, but it works (kind of) except for one little issue where the character is slowly moving to some direction, but it's not the main problem.

The main problem is that I can't set the gravity back to normal. I've tried so many things, i.e Player_SetGravity(1.0f); or Player_SetGravity(-1.0f); or even Player_ChangeStateToNormal();

None of them works, any ideas...? :S

Have you got any other events occurring when Gravity resets so you can confirm the script is actually working? If you can make use of Debug Messages, I really recommend it.

(08-03-2016, 03:53 PM)Darkfire Wrote: So if anything else fails, try my script. It works and looks quite good.

And while it does work, we're working with SOMA here, not Amnesia Wink

Yeah, the script is working. I went through most of SOMA's hps files in codelite searching if they included any information, but found nothing. I doubt that there's a code that would automatically default the gravity, too bad.


RE: Gravity - MrBehemoth - 08-03-2016

There are a couple of things wrong. First off, the function is:
Code:
void Player_SetGravity(const cVector3f &in avGravity)
So that means the argument you give it is a 3d vector, not just a single float value. (So you could have sideways gravity, if that was what you wanted.)

Secondly, this is the actual acceleration due to gravity in metres per second per second, not just a 0-1 multiplier. Normal acceleration due to gravity is about 9.8ms^2 on Earth.

So:
Code:
Player_SetGravity(cVector3f(0.0f, -9.8f, 0.0f)); // Normal downward gravity
Player_SetGravity(cVector3f(0.0f, -4.41f, 0.0f)); // 45% downward gravity

Player_SetGravity(-0.45f); // this is the same as
Player_SetGravity(cVector3f(-0.45f, -0.45f, -0.45f)); // very light, diagonal sideways gravity

I haven't tested it, but I'm fairly sure the first line above will do what you want.


RE: Gravity - Venom Fox - 08-03-2016

(08-03-2016, 06:34 PM)MrBehemoth Wrote: There are a couple of things wrong. First off, the function is:
Code:
void Player_SetGravity(const cVector3f &in avGravity)
So that means the argument you give it is a 3d vector, not just a single float value. (So you could have sideways gravity, if that was what you wanted.)

Secondly, this is the actual acceleration due to gravity in metres per second per second, not just a 0-1 multiplier. Normal acceleration due to gravity is about 9.8ms^2 on Earth.

So:
Code:
Player_SetGravity(cVector3f(0.0f, -9.8f, 0.0f)); // Normal downward gravity
Player_SetGravity(cVector3f(0.0f, -4.41f, 0.0f)); // 45% downward gravity

Player_SetGravity(-0.45f); // this is the same as
Player_SetGravity(cVector3f(-0.45f, -0.45f, -0.45f)); // very light, diagonal sideways gravity

I haven't tested it, but I'm fairly sure the first line above will do what you want.

That helped a lot, thanks! And downwards gravity is what I wanted all along, just didn't know how to do it Tongue Danke!


RE: Gravity - Darkfire - 08-03-2016

Crap, I didn't notice :p