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?
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


Messages In This Thread
How do I make a chair move? - by goodcap - 12-10-2016, 06:57 AM
RE: How do I make a chair move? - by Spelos - 12-10-2016, 10:24 AM
RE: How do I make a chair move? - by Spelos - 12-11-2016, 09:00 AM
RE: How do I make a chair move? - by Mudbill - 12-10-2016, 04:03 PM
RE: How do I make a chair move? - by goodcap - 12-10-2016, 05:16 PM
RE: How do I make a chair move? - by goodcap - 12-10-2016, 07:31 PM
RE: How do I make a chair move? - by Mudbill - 12-10-2016, 07:48 PM
RE: How do I make a chair move? - by goodcap - 12-10-2016, 08:08 PM
RE: How do I make a chair move? - by goodcap - 12-10-2016, 09:17 PM
RE: How do I make a chair move? - by Spelos - 12-12-2016, 08:19 PM
RE: How do I make a chair move? - by Spelos - 12-16-2016, 09:36 AM
RE: How do I make a chair move? - by Daemian - 12-16-2016, 06:01 PM



Users browsing this thread: 1 Guest(s)