Jump to content
mostly

Linking PlayMoveNow to a units speed

Recommended Posts

Hi,

I'm trying to create a script which creates a dog working within a team. I'm using the attachto command to make the dog stay with its handler but want to try and link the dogs animation to the handler's speed. So far I've got this:

 

this addEventHandler ["AnimChanged", 
    {
        params ["_unit", "_anim"];
        
        if (_anim in ["amovpercmstpsraswrfldnon"]) then 
            {                                    
                if (alive SFDog && speed _unit >=1 ) exitWith 
                    {
                        SFDog playMoveNow ("Dog_Walk");
                    };
                    
                if (alive SFDog && speed _unit <1 ) exitWith 
                    {
                        SFDog playMoveNow ("Dog_Idle_02");
                    };
}}];

I know that's really messy but I'm still getting to grips with eventhandlers. I just want it so the dog is idle when the handler has stopped and walks or runs when the handler does.

Any ideas or suggestions would be greatly appreciated. 

Thanks.

Share this post


Link to post
Share on other sites

Hi Mostly.  I'm sure you can modify your code to work as you desire.  But note that there are at least two dog scripts out there that can put a dog under player control or AI control, and these scripts are feature rich (dogs follow, obey commands, attack enemies, etc.).  Maybe these can save you some time or give you some ideas.

 

  • Like 3

Share this post


Link to post
Share on other sites

Thanks Johnnyboy, I've been using your JBOY Dog script for a while but wasn't aware of vDog. I've been looking through the vDog script and found this:

vRunnerAnimationLoop = {
	params["_dog","_runner","_dogOwner","_animalType"];
	while {alive _dog} do {
		if (simulationEnabled _dogOwner && diag_fps > 15) then {
			private _animState = animationState _runner;
			switch (true) do {
				case ((animationState _runner) find "mwlk" >= 0 && speed _runner <= 9): {_dog playMoveNow (_animalType + "_Walk")};
				case ((animationState _runner) find "mrun" >= 0 OR (animationState _runner) find "meva" >= 0 OR speed _runner > 10): {_dog playMoveNow (_animalType + "_Sprint")};
				case ((animationState _runner) find "mrun" >= 0 OR (animationState _runner) find "meva" >= 0 OR speed _runner > 6): {_dog playMoveNow (_animalType + "_Run")};
				case ((animationState _runner) find "mstp" >= 0 OR  speed _runner < 1): {_dog playMoveNow (_animalType + "_Idle_Stop")};
			};
			if (!(animationState _runner isEqualTo _animState)) then {
				_dog setVectorUp (surfaceNormal getpos _runner);  // keep dog feet on ground on slopes
			};	
		};
		sleep 0.5;

I think it is linking the speed of a unit to a playmovenow command, but I can't figure out to make use of it. Anyone got any ideas?

Thanks. 

Share this post


Link to post
Share on other sites

A sort of solution, in case anyone has a similar issue.

while {alive _unit} do {
		if (alive SFDog) then {
			switch (true) do {
				case (speed _unit <1 ): {SFDog playMoveNow ("Dog_Stop")};
				case (speed _unit >1 ): {SFDog playMoveNow ("Dog_Walk")};
				}}}; 

I've had to include this into a separate script as it stopped everything below it from firing. This works though, the dog stands still when the handler is still, and walks when the handler moves. 

I've got my dog script working almost how I want it, but any suggestions to clean up the above would still be appreciated.

Thanks. ✌️

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

×