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
Gravity
Venom Fox Offline
Junior Member

Posts: 32
Threads: 9
Joined: Mar 2016
Reputation: 0
#1
Gravity

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
08-03-2016, 03:05 PM
Find Reply
Darkfire Offline
Senior Member

Posts: 349
Threads: 21
Joined: May 2014
Reputation: 15
#2
RE: Gravity

Maybe Player_SetGravity(0.0f); ?

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

PHP Code: (Select All)
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");



(This post was last modified: 08-03-2016, 03:21 PM by Darkfire.)
08-03-2016, 03:20 PM
Find Reply
Venom Fox Offline
Junior Member

Posts: 32
Threads: 9
Joined: Mar 2016
Reputation: 0
#3
RE: Gravity

(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: (Select All)
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.. :/
08-03-2016, 03:47 PM
Find Reply
Darkfire Offline
Senior Member

Posts: 349
Threads: 21
Joined: May 2014
Reputation: 15
#4
RE: Gravity

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

08-03-2016, 03:53 PM
Find Reply
Romulator Offline
Not Tech Support ;-)

Posts: 3,586
Threads: 62
Joined: Jan 2013
Reputation: 195
#5
RE: Gravity

(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

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 08-03-2016, 05:00 PM by Romulator.)
08-03-2016, 04:59 PM
Find Reply
Venom Fox Offline
Junior Member

Posts: 32
Threads: 9
Joined: Mar 2016
Reputation: 0
#6
RE: Gravity

(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.
08-03-2016, 05:58 PM
Find Reply
MrBehemoth Offline
Senior Member

Posts: 409
Threads: 19
Joined: Feb 2014
Reputation: 40
#7
RE: Gravity

There are a couple of things wrong. First off, the function is:
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:
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.

08-03-2016, 06:34 PM
Find Reply
Venom Fox Offline
Junior Member

Posts: 32
Threads: 9
Joined: Mar 2016
Reputation: 0
#8
RE: Gravity

(08-03-2016, 06:34 PM)MrBehemoth Wrote: There are a couple of things wrong. First off, the function is:
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:
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!
08-03-2016, 06:38 PM
Find Reply
Darkfire Offline
Senior Member

Posts: 349
Threads: 21
Joined: May 2014
Reputation: 15
#9
RE: Gravity

Crap, I didn't notice :p

08-03-2016, 08:58 PM
Find Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Human Verification
Please tick the checkbox that you see below. This process is used to prevent automated spam bots.



Users browsing this thread: 1 Guest(s)