goodcap
Member
Posts: 193
Threads: 112
Joined: Jun 2012
Reputation:
3
|
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 |
|
CarnivorousJelly
Posting Freak
Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation:
80
|
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...
void AddPropForce(string& asName, float afX, float afY, float afZ, string& asCoordSystem); // for pushing the chair, asName is the name of the chair being pushed void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int 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!
|
|
12-10-2016, 09:04 AM |
|
Spelos
Banned
Posts: 231
Threads: 19
Joined: Sep 2014
|
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:
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:
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 * forceMultiplier, playerYinRelationToChair * forceMultiplier, 0.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 |
|
Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
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.
void TimerPushLoop(string &in asTimer) { AddTimer(asTimer, 0.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 |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
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.
|
|
12-10-2016, 04:49 PM |
|
goodcap
Member
Posts: 193
Threads: 112
Joined: Jun 2012
Reputation:
3
|
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 |
|
CarnivorousJelly
Posting Freak
Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation:
80
|
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:
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:
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 * forceMultiplier, playerYinRelationToChair * forceMultiplier, 0.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
|
|
12-10-2016, 06:05 PM |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
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 |
|
goodcap
Member
Posts: 193
Threads: 112
Joined: Jun 2012
Reputation:
3
|
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 |
|
Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
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.
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 |
|
|