Jump to content
Macmachi

vectorAdd doesn't work in MP

Recommended Posts

Hello arma community !

 

I can't move a structure object (props) with vectorAdd in multiplayer. It works very well in solo but it's impossible to use that in multiplayer.

I can't find why it doesn't work and I can't find another solution to solve this problem.

 

Here my code :

while {_x < 10  }


do {

_object1 setPos (getPos _object1 vectorAdd [0,0,10]);

sleep 1;

_x = _x+1;

};

 

Could someone help me?

 

Thank you in advance.

Share this post


Link to post
Share on other sites

Can you show the whole code? Where are you calling this by the way?

  • Like 1

Share this post


Link to post
Share on other sites

Can you clarify what you mean by "multiplayer"? Does it not work in the MP editor? Works for host but not client? Works for no one on dedi?

 

I tried in MP editor and it works fine, so I'm assuming it's another situation.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Macmachi said:

Hello arma community !

 

I can't move a structure object (props) with vectorAdd in multiplayer. It works very well in solo but it's impossible to use that in multiplayer.

I can't find why it doesn't work and I can't find another solution to solve this problem.

 

Here my code :


while {_x < 10  }


do {

_object1 setPos (getPos _object1 vectorAdd [0,0,10]);

sleep 1;

_x = _x+1;

};

 

Could someone help me?

 

Thank you in advance.

 

Without providing any error messages and further details to your problem there's not much that can be done, besides mentioning that _x is a magic variable and shouldn't be used out of context/with operators.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Hi thank you for your answers. Actually, I'm working on a mod.

It's working in solo and in local multiplayer (but when I'm solo). When a friend hosted the game on his machine it didn't work anymore (for him and for me) and on a dedicated server it didn't work either, my object didn't move.

 

Here my complete code from a SQF file that I call into the console or through an addaction. :

_object = ufo;

_b = 1; //iniatialize our variable 

/*Start*/
while {_b < 2000} // (b = b+1 every 0.005 second)

		do { 
		if (_b < 400) then {
		_object setPos (getPos _object vectorAdd [0,0,0.05]);
		sleep 0.005;
		_b = _b+1;
		hintSilent str _b; // debug
		};
		//faster
		if (_b >= 400) then {
		_object setPos (getPos _object vectorAdd [0,0,0.08]);
		sleep 0.005;
		_b = _b+1;
		hintSilent str _b; // debug
		};
		/*End*/
		if (_b == 2000) then {
		deleteVehicle _object; 
		hint "End"; // debug
		};

}; //Close while

 

Share this post


Link to post
Share on other sites
11 minutes ago, Macmachi said:

that I call into the console or through an addaction.

Your code will work in neither debug console nor addAction. Because both of them are unscheduled and you cannot use "sleep" in unscheduled.

 

Also sleep 0.005 is 5 milliseconds. Your script can at most execute once per frame. And one frame is 16.7ms at 60fps.

So

11 minutes ago, Macmachi said:

(b = b+1 every 0.005 second)

Is not correct. the speed will vary depending on FPS and the load other scripts put onto the scheduler. If you run tons of crappy scripts on a client with low fps you might even be so unlucky that your script only executes every few seconds or even minutes. Have fun waiting hours for that animation, that should last 10 seconds, to finish.

 

Also why are you trying to re-purpose a while loop to do the same thing as a for loop? Why not just use a for loop directly? I don't see why setPos should not work in MP.

I guess it might be possible that the distance you are moving it is rounded and that 5cm of movement is just so little that it simply ignores it.

  • Like 1

Share this post


Link to post
Share on other sites
24 minutes ago, Dedmen said:

I guess it might be possible that the distance you are moving it is rounded and that 5cm of movement is just so little that it simply ignores it.

 

This is not the case. I have a building system in place and working where the default increment in distance is 5cm. It works fine.

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, strongground said:

 

This is not the case. I have a building system in place and working where the default increment in distance is 5cm. It works fine.

 

Rounding errors can happen and will be an issue with object placement, have a read.

 

Also the last if check might never return true and the objects deletion will never happen.

If you want smooth movement consider using an EachFrame eventhandler and use delta frametime to calculate the distance needed to move the object.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites
43 minutes ago, Grumpy Old Man said:

If you want smooth movement consider using an EachFrame eventhandler and use delta frametime to calculate the distance needed to move the object.

 

It is on the list of many things to do. :)

However, your advice is most appreciated!

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Grumpy Old Man said:

Rounding errors can happen and will be an issue with object placement, have a read.

Only relevant when converting to string and back which isn't happening here.

Also that post is outdated now that we have toFixed.

 

Floating point precision might cause problems. But only if you go down to millimeter precision.
 

6 hours ago, Dedmen said:

I guess it might be possible that the distance you are moving it is rounded and that 5cm of movement is just so little that it simply ignores it.

With that I meant some hidden engine internals. It might round the number to cm or millimeter internally because more precision might not make sense in devs eyes.

It's still Arma. Not unlikely that such weirdnesses could happen ^^

Share this post


Link to post
Share on other sites

Hello, thanks, everybody!
A friend found a solution. The object I had created was a simple object (not movable). I modified the config.cpp and I use setvelocity with a velocity incrementation in a loop.

Everything works perfectly!

Share this post


Link to post
Share on other sites

Sounds more like a hacky work-around. :grinning:

Share this post


Link to post
Share on other sites
18 hours ago, Macmachi said:

friend found a solution. The object I had created was a simple object (not movable).

Simple objects can be moved just like any other object.

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

×