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.
#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
Credits to Jens for the idea!