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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to "disable" gravity for an entity --EASY TUT--
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#1
How to "disable" gravity for an entity --EASY TUT--

Hello!

This is a quick and surprisingly easy trick I discovered when playing with timer functions.
It makes objects seems to have no real weight and bounce off the walls and even hover a bit!

#1
First, create a simple room in the editor and save the map. It needs to have some movable entities, in my case the books and the skull.

[Image: tut1w.th.png]


#2
Create a .hps file with the name of the map and add the "default" script (I removed the if clause):

////////////////////////////
// Run first time starting map
void OnStart()
{
    GiveItemFromFile("lantern", "lantern.ent");
    for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");  
}

////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}

#3
Now it gets interesting! You can make a script area in the editor but I just put my stuff in OnStart(), no areas needed.
Add a timer in OnStart(), which should look like this:

////////////////////////////
// Run first time starting map
void OnStart()
{
    GiveItemFromFile("lantern", "lantern.ent");
    for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");  
    
    AddTimer("FloatTime", 0.01, "FloatObjects");
}
The short time 0.01 makes sense, just wait and see!

#4
Even more interesting! This is where the magic is at..
I want you to make the function the timer calls and it has to contain these lines:

void FloatObjects(string &in asTimer)
{
    AddPropImpulse("human_skull_1", 0, 0.15, 0, "");
    AddPropImpulse("book01_1", 0, 0.15, 0, "");
    AddPropImpulse("book01_2", 0, 0.15, 0, "");
    AddTimer("FloatTime", 0.01, "FloatObjects");
}

So, what does it do? The coders here may know already, but for everybody else, it's really simple:

The AddPropImpulse adds, like the name says, a specified impulse to the object. The three numbers are the x, y, z coordinates the impulse goes to, in this case we have a very weak impulse going to the y direction, that means UP!
The AddTimer is another timer that calls itself, creating a loop. 0.01 means the time between those calls, it is very short so the player doesn't notice all the little "bounces".

The force you specify makes for very interesting applications, I haven't tested it with bigger objects, but for small stuff everything greater than 0.2 makes the object float upwards. Numbers like 5 make it really fight the ceiling, kinda creepy.. just test what works best for you!

I hope you had fun reading this and trying it out Big Grin

Credits to Jens for the idea!


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
10-04-2010, 08:34 PM
Find
HakePT Offline
Junior Member

Posts: 49
Threads: 1
Joined: Sep 2010
Reputation: 0
#2
RE: How to "disable" gravity for an entity --EASY TUT--

Frontcannon and Jens I proudly present you with...

THE INTERNET!

Congratulations this is some awesome stuff that i may or not end up stealing! Big Grin

If i do use this i will place your name in the credits for all internet to see Wink
10-05-2010, 12:07 AM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#3
RE: How to "disable" gravity for an entity --EASY TUT--

Thanks, I will add this to the wiki, we need more beginner script tutorials Big Grin

The Wiki Tutorial has been added! Go check it out!


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
10-05-2010, 06:07 PM
Find




Users browsing this thread: 2 Guest(s)