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
Script Help How do I make a chair move?
goodcap Offline
Member

Posts: 193
Threads: 112
Joined: Jun 2012
Reputation: 3
#1
How do I make a chair move?

So i'm trying to use a chair as a scare. What I want it to do is:

-Player moves through narrow hallway
-Chair next to a table starts moving a little bit towards the player
(think of paranormal activity)


How do I make this happen?
12-10-2016, 06:57 AM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#2
RE: How do I make a chair move?

I can think of two simple-ish ways of doing this

Method 1: Chair is an Enemy (arguably easiest)
- turn the chair into an entity and then into an enemy (specifically the water monster type)
- edit the files so there aren't any sound effects (perhaps wood scraping when it moves, but that's it)
- edit the .ent file so its movement speed is slow and it does not damage with attacks
- in script: replace a regular chair with the enemy chair-entity when the player hits the trigger point

Method 2: Rough Estimate
If the chair is at one end of the hallway and the player is at the other, all you need to use is
- void AddPropForce(string& asName, float afX, float afY, float afZ, string& asCoordSystem);

Method 3: Rougher Estimate
Have a series of collision areas for the player and push the prop towards those when the player collides with them, this is a combination of...
PHP Code: (Select All)
void AddPropForce(stringasNamefloat afXfloat afYfloat afZstringasCoordSystem);
// for pushing the chair, asName is the name of the chair being pushed
void AddEntityCollideCallback(stringasParentNamestringasChildNamestringasFunctionbool abDeleteOnCollideint alStates);
// for detecting where the player is and where the chair is 
// so you can calculate the vectors needed to push the chair towards the player 

If you need elaboration on the enemy one, let me know!

[Image: quote_by_rueppells_fox-d9ciupp.png]
12-10-2016, 09:04 AM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#3
RE: How do I make a chair move?

I would get the x and y coordinates of both the entity and a player.
Like this:
PHP Code: (Select All)
float playerX;
float playerY;
float chairX;
float chairY;

void NudgeChairTowardsPlayer()
{
    
chairX GetEntityPosX("theChairEntity");
    
chairY GetEntityPosY("theChairEntity");
    
playerX GetPlayerPosX();
    
playerY GetPlayerPosY();


with those variables it's a simple math to get where the player is in relation to the chair. You do that by subtracting the positions. Based on the result you can addPropForce in the right direction.

(optional)
You can add the Z coordinate for pushing even on the Z axis.

You then just need to probably call the NudgeChairTowardsPlayer() function as many times as you want.

EXAMPLE:
PHP Code: (Select All)
float playerX;
float playerY;
float chairX;
float chairY;

void NudgeChairTowardsPlayer()
{
    
chairX GetEntityPosX("theChairEntity");
    
chairY GetEntityPosY("theChairEntity");
    
playerX GetPlayerPosX();
    
playerY GetPlayerPosY();

    
float playerXinRelationToChair playerX chairX;
    
float playerYinRelationToChair playerY chairY;

    
// These will be basically the distance between the chair and the player.
    // Now you can for example multiply the distance to get a strong enough
    // push. According to script wiki the values are ~100 (weak) to ~10000 
    // (strong)

    
float forceMultiplier 500// Play around with this value.

    
AddPropForce("theChairEntity"playerXinRelationToChair forceMultiplierplayerYinRelationToChair forceMultiplier0.0f"world");


Keep in mind, that I haven't tested this code and it serves mainly as a "nudge" in the right direction.
Hope you find it useful.
(This post was last modified: 12-10-2016, 11:42 AM by Spelos.)
12-10-2016, 10:24 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: How do I make a chair move?

I would think Spelos' way should work well, but you might have to execute it within a looping timer to get the effect you want. If you want the chair to slowly scrape along the floor, then giving it many small pushes in order should look pretty alright.

PHP Code: (Select All)
void TimerPushLoop(string &in asTimer) {
    
AddTimer(asTimer0.1f"TimerPushLoop");
    
NudgeChairTowardsPlayer();


With that you can start pushing it by calling TimerPushLoop("NameOfYourTimer");. Remember to call RemoveTimer("NameOfYourTimer"); to stop it or else it will loop forever.

12-10-2016, 04:03 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#5
RE: How do I make a chair move?

Everyone here gave some pretty good examples, although some of them are a bit complicated.
I'm not sure how experienced you are with scripting.

You didn't specify how often and for what purpose the chair is moving.

To me, it sounds like you just want to create a little scare where the chair does a quick push towards the player.
If this is the case, I would go with CJ's solutions:
Have a simple script area. When the player collides with it, use AddPropForce to push the chair a bit in a specific direction.

You said the hallway was narrow, so whether the chair is pushed directly towards the player, or just in his general direciton shouldn't mean much.
As long as the chair moves, it'll appear spooky.

Trying is the first step to success.
(This post was last modified: 12-10-2016, 04:49 PM by FlawlessHappiness.)
12-10-2016, 04:49 PM
Find
goodcap Offline
Member

Posts: 193
Threads: 112
Joined: Jun 2012
Reputation: 3
#6
RE: How do I make a chair move?

I had no idea it would be this difficult to create such a thing haha.


I don't know if any of you have seen the Paranormal Activity movies, but there is this scene where a kid is on a small bike riding through the house and a chair starts moving a little bit to block his patch.

That's what I need.

(I got this idea from a recent custom story, but I forgot it's name. It literally did what I want so I could just copy it, but I can't find it anymore. It was perfect..)
12-10-2016, 05:16 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#7
RE: How do I make a chair move?

(12-10-2016, 10:24 AM)Spelos Wrote: I would get the x and y coordinates of both the entity and a player.
Like this:
PHP Code: (Select All)
float playerX;
float playerY;
float chairX;
float chairY;

void NudgeChairTowardsPlayer()
{
    
chairX GetEntityPosX("theChairEntity");
    
chairY GetEntityPosY("theChairEntity");
    
playerX GetPlayerPosX();
    
playerY GetPlayerPosY();


with those variables it's a simple math to get where the player is in relation to the chair. You do that by subtracting the positions. Based on the result you can addPropForce in the right direction.

(optional)
You can add the Z coordinate for pushing even on the Z axis.

You then just need to probably call the NudgeChairTowardsPlayer() function as many times as you want.

EXAMPLE:
PHP Code: (Select All)
float playerX;
float playerY;
float chairX;
float chairY;

void NudgeChairTowardsPlayer()
{
    
chairX GetEntityPosX("theChairEntity");
    
chairY GetEntityPosY("theChairEntity");
    
playerX GetPlayerPosX();
    
playerY GetPlayerPosY();

    
float playerXinRelationToChair playerX chairX;
    
float playerYinRelationToChair playerY chairY;

    
// These will be basically the distance between the chair and the player.
    // Now you can for example multiply the distance to get a strong enough
    // push. According to script wiki the values are ~100 (weak) to ~10000 
    // (strong)

    
float forceMultiplier 500// Play around with this value.

    
AddPropForce("theChairEntity"playerXinRelationToChair forceMultiplierplayerYinRelationToChair forceMultiplier0.0f"world");


Keep in mind, that I haven't tested this code and it serves mainly as a "nudge" in the right direction.
Hope you find it useful.

Spelos, you'd want the X and Z coordinates. Y is vertical in HPL2

[Image: quote_by_rueppells_fox-d9ciupp.png]
12-10-2016, 06:05 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#8
RE: How do I make a chair move?

(12-10-2016, 05:16 PM)goodcap Wrote: I had no idea it would be this difficult to create such a thing haha.


I don't know if any of you have seen the Paranormal Activity movies, but there is this scene where a kid is on a small bike riding through the house and a chair starts moving a little bit to block his patch.

That's what I need.

(I got this idea from a recent custom story, but I forgot it's name. It literally did what I want so I could just copy it, but I can't find it anymore. It was perfect..)

If you just want it to block the player's path, just have the player collide with a script area, and then use AddPropForce to push over the chair.

Trying is the first step to success.
12-10-2016, 06:22 PM
Find
goodcap Offline
Member

Posts: 193
Threads: 112
Joined: Jun 2012
Reputation: 3
#9
RE: How do I make a chair move?

(12-10-2016, 06:22 PM)FlawlessHappiness Wrote:
(12-10-2016, 05:16 PM)goodcap Wrote: I had no idea it would be this difficult to create such a thing haha.


I don't know if any of you have seen the Paranormal Activity movies, but there is this scene where a kid is on a small bike riding through the house and a chair starts moving a little bit to block his patch.

That's what I need.

(I got this idea from a recent custom story, but I forgot it's name. It literally did what I want so I could just copy it, but I can't find it anymore. It was perfect..)

If you just want it to block the player's path, just have the player collide with a script area, and then use AddPropForce to push over the chair.

I found the movie scene hehe. This is what I want it to do:

https://youtu.be/BsMtMPGIPOg?t=35m52s
12-10-2016, 07:31 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#10
RE: How do I make a chair move?

Ok, well, I think then the safest (and possibly simplest though subjective) way would be:

Create a custom entity for the chair by opening the original and "Save As" a different name. Make it a MoveObject type. Set the axis to be the direction you want the chair to move in the level (either X or Z). You do this in the User Defined Variables in the Model Editor.

Spoiler below!
[Image: f53474051df7413b80fd10e37db1effb.png]

In the map, place the entity. Once the player hits a collision box, use SetMoveObjectState to move the chair along the axis. That's all you need to do.

In the User Defined Variables you can also specify the speed and accelleration of the chair, but instead of doing it here, you can use the function SetMoveObjectStateExt instead to specify it in the script (it's a bit easier if you need to change values often).

PS: If you want the player to be able to also grab the chair after it has moved, use ReplaceEntity to turn the entity back into a normal chair (which is a Grab object).



However if you don't mind the chair possibly falling over, you can probably just use the function AddPropForce alone...

(This post was last modified: 12-10-2016, 08:01 PM by Mudbill.)
12-10-2016, 07:48 PM
Find




Users browsing this thread: 1 Guest(s)