Jump to content
Sign in to follow this  
tpw

Realistic falling script - how to detect which weapon a unit is holding

Recommended Posts

I really can't stand the way units barely react to falling, it's as though they have no inertia. I've decided to try to do something about it by resurrecting a very simple script I wrote a while ago (http://forums.bistudio.com/showthread.php?113984-How-to-detect-if-player-unit-is-falling) that keeps track of the player's vertical speed, and triggers a fall/roll and get back up again if the vertical speed exceed -4.5m/s, which is about the speed reached after a 2m fall.

/*
TPW_FALL
20130701
Player will hit ground and roll after falling from greater than 2m
*/

// VARIABLES
_int = 0.1; // how often should player vertical speed be polled
_thresh = -4.5; // speed in m/s above which falling animation is triggered -4.5m/s is vertical speed after falling from about 2m

// MAIN LOOP
while {((alive player) and (vehicle player iskindof "man"))} do 
{
_v1 = velocity player select 2;
if (_v1 < _thresh) then 
	{
	player switchmove "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright"; //roll right
	sleep 1;
	player playmove "AadjPpneMstpSrasWrflDright_AmovPercMstpSrasWrflDnon"; //get up again
	sleep 3;
	};
sleep _int;		
};

The script works very well as it is, however it currently only displays the roll and get back up animations for the player with a primary weapon. I'd like to have it display the appropriate animations for handgun and launcher, but cannot work out a way using existing scripting commands to detect whether the player is holding a primary/secondary/launcher. I figure it is probably going to involve querying configs, but don't know how to go about it.

So, if anyone has any bright ideas about how to best query the held weapon status of a unit, I'd love to hear them!

Edited by tpw

Share this post


Link to post
Share on other sites

what about:

If (currentWeapon _unit == primaryWeapon _unit) ....

Share this post


Link to post
Share on other sites
what about:

If (currentWeapon _unit == primaryWeapon _unit) ....

Sigh, so simple, no wonder I never thought of it. Works perfectly, thanks zapat.

/*
TPW_FALL
20130701
Player will hit ground and roll/kneel after falling from greater than 2m
*/

// VARIABLES
_int = 0.1; // how often should player vertical speed be polled
_thresh = -5; // speed in m/s above which falling animation is triggered -4.5m/s is vertical speed after falling from about 2m

// MAIN LOOP
while {((alive player) and (vehicle player iskindof "man"))} do 
{
_v1 = velocity player select 2;

if (_v1 < _thresh) then 
	{
	_cw = currentweapon player;
	_hg = handgunweapon player;
	_pw = primaryweapon player;
	_sw = secondaryweapon player;

	switch _cw do 
		{
		case "": 
			{
			player switchmove "AmovPercMstpSnonWnonDnon_AinvPknlMstpSnonWnonDnon"; // kneel with no weapons
			sleep 1;
			player playmove "AmovPknlMstpSnonWnonDnon_AmovPercMstpSnonWnonDnon"; // get up again
			sleep 3;
			};
		case _hg: 
			{
			player switchmove "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft";// roll left with pistol
			sleep 1;
			player playmove "AadjPpneMstpSrasWpstDleft_AmovPercMstpSrasWpstDnon";//get up again
			sleep 3;
			};
		case _pw:
			{
			player switchmove "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright"; // roll right with rifle
			sleep 1;
			player playmove "AadjPpneMstpSrasWrflDright_AmovPercMstpSrasWrflDnon"; //get up again
			sleep 3;
			};
		case _sw: 
			{
			player switchmove "AmovPercMstpSrasWlnrDnon_AmovPpneMstpSnonWnonDnon"; // prone with launcher
			sleep 3;
			};
		};
	};	
sleep _int;		
};

At present you'll get a different falling animation for unarmed, pistol, rifle and launcher. Now all I need is a decent sound effect, such as one of the player footsteps, but again I have no idea how to access the footstep noises.

Share this post


Link to post
Share on other sites

This is super Groovy TPW... Another one of those simple things that should be part of the game by default.. Thanks and i cant wait to see it in action.

Do you have any plans on making this an addon or leaving it as a script? Can i plead for an addon version for ease of use in SP, IE not having to manually add it to every mission?.

Share this post


Link to post
Share on other sites
This is super Groovy TPW... Another one of those simple things that should be part of the game by default.. Thanks and i cant wait to see it in action.

Do you have any plans on making this an addon or leaving it as a script? Can i plead for an addon version for ease of use in SP, IE not having to manually add it to every mission?.

This plus a video showing the progress would be nice. ;)

Share this post


Link to post
Share on other sites

Thanks guys. I will certainly make it into an addon once it's a little bit more mature, and I will have a crack at recording it too. If anyone wants to try it in the mean time and provide a bit of feedback...

Share this post


Link to post
Share on other sites

Tried it and it works pretty well.

Can you have the player go back to the stance they were in before the fall?

Otherwise not bad!

Share this post


Link to post
Share on other sites

Hello tpw,

thank you so much for your "little" ideas.

I never missed this "realistic fall" - ´til today...great mate!

Good to know that people, like you, have the skill (idea) to create this feature. :bounce3:

Cheers

McLupo

Share this post


Link to post
Share on other sites

OK guys, here's a more mature effort for you to test out. If it passes muster then I'll turn it into an addon.

TPW FALL v1.00:

  • Player character now reacts to falls of more than about 1m
  • Small falls trigger a landing noise only
  • Larger falls trigger landing and falling to ground noises, and appropriate animations
  • Running over rough/rocky terrain can trigger a fall, to simulate tripping

Code below. Just save it into your mission directory as tpw_fall.sqf, and call it from your init.sqf or player init with 0 = [] execvm "tpw_fall.sqf";

// THIS SCRIPT WON'T RUN ON DEDICATED SERVERS
if (isDedicated) exitWith {};

/*
TPW_FALL
Version: 1.00
Author: tpw
Date: 20130702
Thanks: Lifted86, zapat

Player character now reacts to falls of more than about 1m
Small falls trigger a landing noise only
Larger falls trigger landing and falling to ground noises, and appropriate animations
Running over rough/rocky terrain can trigger a fall, to simulate tripping
*/

// VARIABLES
private ["_int","_small","_thresh","_steparray","_crawlarray","_crawlarray2","_yellarray","_downarray","_uparray","_stepcount","_yellcount","_crawlcount","_crawlcount2"];
_int = 0.1; // how often should player's vertical speed be polled (sec)
_small = -2; // speed in m/s above which landing footstep noises are triggered
_thresh = -5; // speed in m/s above which falling animation is triggered. -4.5m/s is vertical speed after falling from about 2m
_steparray = ["gravel_run_1","gravel_run_2","gravel_run_3","gravel_run_4","gravel_run_5","gravel_run_6","gravel_run_7"]; // footstep noises for landing
_crawlarray = ["crawl_dirt_1","crawl_dirt_2","crawl_dirt_3","crawl_dirt_4","crawl_dirt_5","crawl_dirt_6","crawl_dirt_7"]; // crawl noises for fall after landing
_crawlarray2 = ["crawl_grass_01","crawl_grass_02","crawl_grass_03","crawl_grass_04","crawl_grass_05","crawl_grass_06","crawl_grass_07"]; // crawl noises for getting back up
_yellarray = ["Ooofff!","Ouch!", "Ahh!","Not pretty!","Shit!","Ooohh you little bastard!"]; // yells after falling
_downarray = ["AmovPercMstpSnonWnonDnon_AinvPknlMstpSnonWnonDnon","AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft","AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright","AmovPercMstpSrasWlnrDnon_AmovPpneMstpSnonWnonDnon"]; // Falling down animations
_uparray = ["AmovPknlMstpSnonWnonDnon_AmovPercMstpSnonWnonDnon","AadjPpneMstpSrasWpstDleft_AmovPercMstpSrasWpstDnon","AadjPpneMstpSrasWrflDright_AmovPercMstpSrasWrflDnon"]; // Getting back up animations

//COUNT ARRAY CONTENTS
_stepcount = count _steparray;
_crawlcount = count _crawlarray;
_crawlcount2 = count _crawlarray2;
_yellcount = count _yellarray;

//FUNCTIONS
tpw_falldown = 
{
private ["_step","_stepsound","_move","_yell","_crawl","_crawlsound"];
// random landing noise
_step = _steparray select (floor (random _stepcount)); 
_stepsound = format ["A3\sounds_f\characters\footsteps\%1.wss",_step];
playSound3D [_stepsound, player,false,getpos player,1,1,0]; // initial thump of feet
// fall animation
_move = _this select 0;
player switchmove _move;
// player yells
_yell = _yellarray select (floor (random _yellcount)); 
player groupchat _yell;
sleep 1;
// random falling noise
_crawl = _crawlarray select (floor (random _crawlcount)); 	
_crawlsound = format ["A3\sounds_f\characters\crawl\%1.wss",_crawl];
playSound3D [_crawlsound, player,false,getpos player,0.3,1,0]; // fall to ground noise
};

tpw_getup = 
{
private ["_move","_crawl2","_crawlsound2"];
//random get up noise
_crawl2 = _crawlarray2 select (floor (random _crawlcount2)); 
_crawlsound2 = format ["A3\sounds_f\characters\crawl\%1.wss",_crawl2];
playSound3D [_crawlsound2, player,false,getpos player,0.3,1,0]; // get up noise
// get up animation
_move = _this select 0;
player playmove _move;
};

// STARTUP HINT	
sleep 2;
[] spawn {
hintsilent "TPW Fall 1.00 active";
sleep 3;
hintsilent "";
};	


// MAIN LOOP, ONLY IF PLAYER ON FOOT
while {((alive player) and (vehicle player iskindof "man"))} do 
{
private ["_v1","_v2","_cw","_hw","_pw","_sw"];
// Player's vertical speed
_v1 = velocity player select 2;
sleep _int;	
_v2 = velocity player select 2;
//If player's fall is slowing (ie they have landed) 
if (_v2 > _v1) then 
	{
	//Small falls
	if ((_v1 < _small) and (_v1 > _thresh)) then 
		{
		// Landing noise only
		_step = _steparray select (floor (random _stepcount)); 
		_stepsound = format ["A3\sounds_f\characters\footsteps\%1.wss",_step];
		playSound3D [_stepsound, player,false,getpos player,0.5,1,0]; 
		};
	//Large falls	
	if (_v1 < _thresh) then 
		{
		//Weapon status
		_cw = currentweapon player;
		_hw = handgunweapon player;
		_pw = primaryweapon player;
		_sw = secondaryweapon player;
		//Switch to appropriate animations depending on whether player has rifle/pistol/launcher/no weapon
		switch _cw do 
			{
			case "": 
				{
				0 = [_downarray select 0] call tpw_falldown;
				sleep 1;
				0 = [_uparray select 0] call tpw_getup;
				sleep 3;
				};
			case _hw: 
				{
				0 = [_downarray select 1] call tpw_falldown;
				sleep 1;
				0 = [_uparray select 1] call tpw_getup;
				sleep 3;
				};
			case _pw:
				{
				0 = [_downarray select 2] call tpw_falldown;
				sleep 1;
				0 = [_uparray select 2] call tpw_getup;
				sleep 3;
				};
			case _sw: 
				{
				0 = [_downarray select 3] call tpw_falldown;
				};
			};
		} ;
	};		
};

Any feedback appreciated.

Known issues:

  • A small visual glitch in 1st person when fall animation is triggered.
  • Landing sounds are quite loud in 3rd person
  • I've no idea if it runs in MP

And McLupo, thanks once again for your kind words!

Edited by tpw

Share this post


Link to post
Share on other sites

This is cool: a nice idea with simple execution! And so much it adds to the atmosphere. Falling had brought back the late 90s before this. :)

Note 1: you could check for isSurfaceWater or getPosASL select 2 < 0 (maybe getTerrainheightASL select 2 < 0), because some may love jumping from piers too (when A3 is their holiday simulator as well, ha ha).

Note 2: doesn't the loop stops if player gets in a car?

why don't you use:

while {alive player} do 
{
  if (player == vehicle player) then
  {
       //rest of the code
  };
};

Edited by zapat

Share this post


Link to post
Share on other sites

Will test this after updating (roughly in one hour). Will edit the results in this post. :p

Looks nice so far. Would it be possible to ignore moving foward/backward when in the prone stance animation? I always move forth - well, sidewards - when I fall.

Edited by SeiFe

Share this post


Link to post
Share on other sites

Hello, once again! :)

It will be reviewed after the release, that´s for sure, but in the meantime have fun with

the short visualized impression...

Thanks tpw for your ongoing effort to realize your great ideas and sharing them.

All my credits to YOU!!!

Have fun:

Share this post


Link to post
Share on other sites

Nice TPW !! Another good one. What about going to ragdoll if over 5m then the ability to heal :)

Possible to have it as a baby addon ?

Also no forward roll animations I take it ?

Edited by Kremator

Share this post


Link to post
Share on other sites
This is cool: a nice idea with simple execution! And so much it adds to the atmosphere. Falling had brought back the late 90s before this. :)

Note 1: you could check for isSurfaceWater or getPosASL select 2 < 0 (maybe getTerrainheightASL select 2 < 0), because some may love jumping from piers too (when A3 is their holiday simulator as well, ha ha).

Note 2: doesn't the loop stops if player gets in a car?

why don't you use:

while {alive player} do 
{
  if (player == vehicle player) then
  {
       //rest of the code
  };
};

Thanks zapat. I will definitely implement the water check.

The loop should stop when a player gets in a vehicle:

while {((alive player) and (vehicle player iskindof "man"))} do

vehicle player iskindof "man" should return false in a car/plane/boat:

Edit: Ah, I see what you mean, the loop will stop and not restart. I will change that ASAP.

---------- Post added at 06:12 ---------- Previous post was at 06:10 ----------

Will test this after updating (roughly in one hour). Will edit the results in this post. :p

Looks nice so far. Would it be possible to ignore moving foward/backward when in the prone stance animation? I always move forth - well, sidewards - when I fall.

No worries, I'll look into it

---------- Post added at 06:13 ---------- Previous post was at 06:12 ----------

Hello, once again! :)

It will be reviewed after the release, that´s for sure, but in the meantime have fun with

the short visualized impression...

Thanks tpw for your ongoing effort to realize your great ideas and sharing them.

All my credits to YOU!!!

Have fun

Thanks so much McLupo!

---------- Post added at 06:16 ---------- Previous post was at 06:13 ----------

Nice TPW !! Another good one. What about going to ragdoll if over 5m then the ability to heal :)

Possible to have it as a baby addon ?

Also no forward roll animations I take it ?

I'll look into ragdoll, but promise nothing...

Addon coming today!

No forward roll animations sorry. Believe me I checked them all out, and had to make do with the ones you can see.

Edited by tpw

Share this post


Link to post
Share on other sites

Absolutely love it!

Sometimes after landing the character will be stuck in a 'ice-slide' type animation for a few seconds.

Share this post


Link to post
Share on other sites

Thanks for the input and advice everyone. Here's a new version.

TPW FALL v1.01

  • Can be called for any unit, not just player
  • Falls into water trigger splashing
  • Removed ability to inadvertently slide after landing
  • Script will work correctly when units enter/exit vehicles
  • Adjusted pitch, volume and attenuation of sounds, will sound better in 3rd person

Usage:

Save script below into mission directory as tpw_fall.sqf

In editor: Place 0 = [this] execvm "tpw_fall.sqf" into the init of any unit you want to react to falling

Via init.sqf or similar:

Player only: 0 = [player] execvm "tpw_fall.sqf";

Squad: {0 = [_x] execvm "tpw_fall.sqf";} foreach units (group player);

Every unit: {0 = [_x] execvm "tpw_fall.sqf";} foreach allunits;

Code:

// THIS SCRIPT WON'T RUN ON DEDICATED SERVERS
if (isDedicated) exitWith {};

/*
TPW_FALL
Version: 1.01
Author: tpw
Date: 20130703
Thanks: Lifted86, zapat

Infantry reacts to falls.
Small falls trigger landing noises only.
Larger falls trigger landing and falling noises, and appropriate animations.
Falls over water trigger splashing noise.
*/

// VARIABLES
private ["_unit","_int","_att","_small","_thresh","_steparray","_crawlarray","_crawlarray2","_yellarray","_splasharray","_downarray","_uparray","_stepcount","_yellcount","_splashcount","_crawlcount","_crawlcount2"];
_unit = _this select 0;
_int = 0.1; // how often should _unit's vertical speed be polled (sec)
_att = 25; //sound attenuation distance
_small = -2; // speed in m/s above which landing footstep noises are triggered
_thresh = -5; // speed in m/s above which falling animation is triggered. -4.5m/s is vertical speed after falling from about 2m
_steparray = ["gravel_run_1","gravel_run_2","gravel_run_3","gravel_run_4","gravel_run_5","gravel_run_6","gravel_run_7"]; // footstep noises for landing
_crawlarray = ["crawl_dirt_1","crawl_dirt_2","crawl_dirt_3","crawl_dirt_4","crawl_dirt_5","crawl_dirt_6","crawl_dirt_7"]; // crawl noises for fall after landing
_crawlarray2 = ["crawl_grass_01","crawl_grass_02","crawl_grass_03","crawl_grass_04","crawl_grass_05","crawl_grass_06","crawl_grass_07"]; // crawl noises for getting back up
_splasharray = ["water_sprint_1","water_sprint_2","water_sprint_3","water_sprint_4","water_sprint_5","water_sprint_6","water_sprint_7","water_sprint_8"]; // splash noises for landing in water
_yellarray = ["Ooofff!","Ouch!", "Ahh!","Not pretty!","Shit!","Ooohh you little bastard!"]; // yells after falling
_downarray = ["AmovPercMstpSnonWnonDnon_AinvPknlMstpSnonWnonDnon","AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft","AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright","AmovPercMstpSrasWlnrDnon_AmovPpneMstpSnonWnonDnon"]; // Falling down animations
_uparray = ["AmovPknlMstpSnonWnonDnon_AmovPercMstpSnonWnonDnon","AadjPpneMstpSrasWpstDleft_AmovPercMstpSrasWpstDnon","AadjPpneMstpSrasWrflDright_AmovPercMstpSrasWrflDnon"]; // Getting back up animations

//COUNT ARRAY CONTENTS
_stepcount = count _steparray;
_crawlcount = count _crawlarray;
_crawlcount2 = count _crawlarray2;
_yellcount = count _yellarray;
_splashcount = count _splasharray;

//FUNCTIONS
tpw_falldown = 
{
private ["_step","_stepsound","_move","_yell","_crawl","_crawlsound"];

// random landing noise
_step = _steparray select (floor (random _stepcount)); 
_stepsound = format ["A3\sounds_f\characters\footsteps\%1.wss",_step];
playSound3D [_stepsound, _unit,false,getpos _unit,3,0.7,_att]; // initial thump of feet
// fall animation
_move = _this select 0;
_unit switchmove _move;
// _unit yells
_yell = _yellarray select (floor (random _yellcount)); 
_unit groupchat _yell;
sleep 1;
// random falling noise
_crawl = _crawlarray select (floor (random _crawlcount)); 	
_crawlsound = format ["A3\sounds_f\characters\crawl\%1.wss",_crawl];
playSound3D [_crawlsound, _unit,false,getpos _unit,1,1,_att]; // fall to ground noise
};

tpw_getup = 
{
private ["_move","_crawl2","_crawlsound2"];
//random get up noise
_crawl2 = _crawlarray2 select (floor (random _crawlcount2)); 
_crawlsound2 = format ["A3\sounds_f\characters\crawl\%1.wss",_crawl2];
playSound3D [_crawlsound2, _unit,false,getpos _unit,1,1,_att]; // get up noise
// get up animation
_move = _this select 0;
_unit playmove _move;
};

// STARTUP HINT	
sleep 2;
[] spawn {
hintsilent "TPW Fall 1.01 active";
sleep 3;
hintsilent "";
};	

// MAIN LOOP, ONLY IF UNIT  ON FOOT
while {alive _unit} do 
{
if (_unit == vehicle _unit) then 
   {
	private ["_v1","_v2","_cw","_hw","_pw","_sw"];
	// _unit's vertical speed
	_v1 = velocity _unit select 2;
	sleep _int;	
	_v2 = velocity _unit select 2;
	//If _unit's fall is slowing (ie they have landed) 
	if ((_v2 > _v1) and (_v1 < 0)) then 
		{
		//Is _unit on water?
		_posx = (getpos _unit) select 0;
		_posy = (getpos _unit) select 1;
		if (!(surfaceiswater [_posx,_posy])) then 	
			{
			//Small falls
			if ((_v1 < _small) and (_v1 > _thresh)) then 
				{
				// Landing noise only
				_step = _steparray select (floor (random _stepcount)); 
				_stepsound = format ["A3\sounds_f\characters\footsteps\%1.wss",_step];
				playSound3D [_stepsound, _unit,false,getpos _unit,1,1,_att]; 
				};
			//Large falls	
			if (_v1 < _thresh) then 
				{
				//Weapon status
				_cw = currentweapon _unit;
				_hw = handgunweapon _unit;
				_pw = primaryweapon _unit;
				_sw = secondaryweapon _unit;
				//Switch to appropriate animations depending on whether _unit has rifle/pistol/launcher/no weapon
				switch _cw do 
					{
					case "": 
						{
						0 = [_downarray select 0] call tpw_falldown;
						sleep 1;
						0 = [_uparray select 0] call tpw_getup;
						sleep 3;
						};
					case _hw: 
						{
						0 = [_downarray select 1] call tpw_falldown;
						0 = [_uparray select 1] call tpw_getup;
						sleep 3;
						};
					case _pw:
						{
						0 = [_downarray select 2] call tpw_falldown;
						0 = [_uparray select 2] call tpw_getup;
						sleep 3;
						};
					case _sw: 
						{
						0 = [_downarray select 3] call tpw_falldown;
						};
					};
				} ;
			} else
			{
			if (_v1 < _small) then 
				{
				// random splashing noise
				_splash = _splasharray select (floor (random _splashcount)); 
				_splashsound = format ["A3\sounds_f\characters\footsteps\%1.wss",_splash];
				playSound3D [_splashsound, _unit,false,getpos _unit,2,0.3,_att]; 
				sleep 3;
				};
			};
		};	
	};			
};[code][php]

[/code][/php]

I will make an addon shortly.

-------------------------

EDIT: I have now released this as a proper addon: http://forums.bistudio.com/showthread.php?158398-TPW-FALL-realistic-infantry-falling-system&p=2431979#post2431979

Edited by tpw

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×