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
Making an entity fly
xtron Offline
Senior Member

Posts: 402
Threads: 37
Joined: May 2011
Reputation: 2
#1
Making an entity fly

How to use the function "AddPlayerBodyForce(float afX, float afY, float afZ, bool abUseLocalCoords);" ?


Sorry for spaming this forum with my "help please" shit. But this is my first time making an map and scripting to Amnesia so I need some help Smile. Thanks for all the help i already got. You guys are lovely.

[Image: 44917299.jpg]Dubstep <3
(This post was last modified: 05-26-2011, 08:18 PM by xtron.)
05-26-2011, 08:11 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: Making an entity fly

(05-26-2011, 08:11 PM)xtron Wrote: How to use the function "AddPlayerBodyForce(float afX, float afY, float afZ, bool abUseLocalCoords);" ?


Sorry for spaming this forum with my "help please" shit. But this is my first time making an map ands cripting to Amnesia so I need some help Smile. Thanks for all the help i already got. You guys are lovely.

In the case of any non-player entity, you will want:
AddPropForce("<object name here>", 0, <force here>, 0, "world");
Being called once every 1/60th of a second (by a timer). To work out what "<force>" is you are going to have to just experiment, as it is different for every object. The "AddPlayerBodyForce" is exactly the same except the first argument is omitted, as the object is already specified as the player.
(This post was last modified: 05-26-2011, 08:18 PM by Apjjm.)
05-26-2011, 08:18 PM
Find
xtron Offline
Senior Member

Posts: 402
Threads: 37
Joined: May 2011
Reputation: 2
#3
RE: Making an entity fly

(05-26-2011, 08:18 PM)Apjjm Wrote: In the case of any non-player entity, you will want:
AddPropForce("<object name here>", 0, <force here>, 0, "world");
Being called once every 1/60th of a second (by a timer). To work out what "<force>" is you are going to have to just experiment, as it is different for every object. The "AddPlayerBodyForce" is exactly the same except the first argument is omitted, as the object is already specified as the player.

The thing is that I'm gonna do so when you enter a door and you walk in you're gonna get pushed out of the room and the door with lock.

[Image: 44917299.jpg]Dubstep <3
(This post was last modified: 05-26-2011, 08:23 PM by xtron.)
05-26-2011, 08:22 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#4
RE: Making an entity fly

(05-26-2011, 08:22 PM)xtron Wrote: The thing is that I'm gonna do so when you enter a door and you walk in you're gonna get pushed out of the room and the door with lock.

So you want to push the player out a room? Here's a guide:

Note: We are assuming for this that the player is coming through the door to the room, and not arbitrarily placed inside the room. This case is much simpler than the latter, and probably the case you are after.


First the arguments of "AddPlayerBodyForce":
"afX" is the X-component of the force, afY the Y-component etc. You want to be using false as "abUseLocalCoords", unless you can guarantee the direction the player is facing (By using a look-at script).

To work out what components you want you need to take a look in the level editor at your door. Make a box, and imagine it is the player for now; Place it by your door and move it to where you want the player to go, roughly speaking. Take note of the position fields in the object properties before and after you do this - and now do a little bit of maths to calculate the change in position (Final location - starting location : Signs are important here!).
You now have the direction to push the player in, in components. These are the afX, afY and afZ values pretty much. But we ain't there yet - the function wants a force - we just have a change in position!

As you are applying a brief impulse, we can skip complex maths shenanigans, and get straight to the trial and error part:
float mult = 1500.0f;
AddPlayerBodyForce(mult * afX, mult * afY, mult * afZ, false);

What we are trying to do here, is approximate the mass of the player, and slightly adjust the force you have already got. To do this effectively you want a single point of control called "mult" so you can tweak all your values to get the right force without having to re-calculate the arguments to the force function over, and over, and over.
Remember, The player is pretty heavy, but you now just have to experiment to see what value of "mult" gets the effect you are after.
(This post was last modified: 05-26-2011, 11:08 PM by Apjjm.)
05-26-2011, 11:07 PM
Find
xtron Offline
Senior Member

Posts: 402
Threads: 37
Joined: May 2011
Reputation: 2
#5
RE: Making an entity fly

void OnStart()
{
AddEntityCollideCallback("Player", "script_push_player1", "push_player_close_lock_door1", true, 1);
}

void push_player_close_lock_door1(string &in asParent, string &in asChild, int alState)
{
    float mult = 1500.0f;
    AddPlayerBodyForce("-54.25", "0", ""-0.3, false);
}

The yellow dot is were the player will be pushed to. I draged the door and placed it where i wanted the player to be pushed to and then took the coordinates.
Spoiler below!

[Image: pushc.png]

Uploaded with ImageShack.us


This is my pic of where to be pushed and where you're gonna get pushed. Is it alright?

[Image: 44917299.jpg]Dubstep <3
(This post was last modified: 05-27-2011, 02:27 PM by xtron.)
05-27-2011, 02:27 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#6
RE: Making an entity fly

The picture looks fine. Is that displacement on the x-axis really -54.25 units though - looks more like 4. Remember: place you want the player to be take away the place the player currently is. E.g:
Start X: 50 End X: 20 aFX: -30
Start Y: 00 End Y: 01 aFY: 01
Start Z: 00 End Z: 03 aFZ: 03


As long as you can reasonably be sure of no obstructions between the player and his goal, there shouldn't be an issue. Adjust the code to the following, though - otherwise you aren't using the multiplication and scaling your calculation appropriately.
void push_player_close_lock_door1(string &in asParent, string &in asChild, int alState)
{
    float mult = 1500.0f;
    AddPlayerBodyForce(mult * -54.25, 0, mult * -0.3, false);
        //OR Perhaps:
        //AddPlayerBodyForce(mult * 4, 0, 0, false);
}


(This post was last modified: 05-27-2011, 03:37 PM by Apjjm.)
05-27-2011, 03:28 PM
Find
xtron Offline
Senior Member

Posts: 402
Threads: 37
Joined: May 2011
Reputation: 2
#7
RE: Making an entity fly

(05-27-2011, 03:28 PM)Apjjm Wrote: The picture looks fine. Is that displacement on the x-axis really -54.25 units though - looks more like 4. Remember: place you want the player to be take away the place the player currently is. E.g:
Start X: 50 End X: 20 aFX: -30
Start Y: 00 End Y: 01 aFY: 01
Start Z: 00 End Z: 03 aFZ: 03


As long as you can reasonably be sure of no obstructions between the player and his goal, there shouldn't be an issue. Adjust the code to the following, though - otherwise you aren't using the multiplication and scaling your calculation appropriately.
void push_player_close_lock_door1(string &in asParent, string &in asChild, int alState)
{
    float mult = 1500.0f;
    AddPlayerBodyForce(mult * -54.25, 0, mult * -0.3, false);
        //OR Perhaps:
        //AddPlayerBodyForce(mult * 4, 0, 0, false);
}

Now he's being pushed forward...or...he's not even being pushed, he's running Tongue. Thanks btw but do you know the code so he gets pushed out of the room?.

EDIT!: Nvm I fixed it Big Grin. I changed "-54.25" to "54.25 ^^.

[Image: 44917299.jpg]Dubstep <3
(This post was last modified: 05-27-2011, 11:07 PM by xtron.)
05-27-2011, 11:04 PM
Find




Users browsing this thread: 1 Guest(s)