Home   Help Search Login Register  

Author Topic: setVectorDir, setVectorUp and setVelocity in MP  (Read 8138 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
setVectorDir, setVectorUp and setVelocity in MP
« on: 17 Apr 2007, 10:54:03 »
Anyone did any test with any of these in MP? Do they work?

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #1 on: 17 Apr 2007, 15:20:06 »
I'll probably put my foot in my mouth here...  :shhh:
My guess is that they will act properly on when executed on the local client. They will still work for non-local units, but any changes will disappear with the next synchronisation. So for all server controlled units, you need only execute these commands on the server. However, if you want to guarantee all players see the same effect, and your script is neither computationally expensive nor involves random numbers, there is nothing wrong with running it on all clients and the server.

Okay, long pause as I open my mouth wide and prepare to stick my foot in...
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #2 on: 17 Apr 2007, 15:41:41 »
mmm running the script in all clients would not guarantee same effect as all these commands are quite dependant on the "speed" of the machine, I mean, you may make a unit turn 360 degrees smoothly in 10 secs in machine A and 15 secs in machine B, at some point clent A and client B will see the object pointing at different directions.

long pause as I open my mouth wide and prepare to stick my foot in too  :blink:

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #3 on: 17 Apr 2007, 16:00:09 »
This is true. I guess which is better will depend on the amount of network lag. Big lag would make the local solution better. I did also say for scripts that were not too computationally intensive local solution would be okay. For fast looping scripts with lots of short pauses.. not okay.

My helicopter collision avoidance script I wrote for OFP(only used setVelocity) worked fine in MP run server only because it only affected enemy ai helicopters. (aside: my recent test for ArmA revealed that ai pilots are significantly better at avoiding collisions with each other, but still collide too much.)
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #4 on: 17 Apr 2007, 16:13:52 »
Definitively I'm lacking way too much MP scripting  knowledge ??? that, or MP scripting is plainly absurd  :blink:

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #5 on: 17 Apr 2007, 16:26:26 »
I would say, if possible, try to launch commands impacting a unit on the PC where this unit is local, be it the server or a client PC.

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #6 on: 17 Apr 2007, 16:50:26 »
Mandoble,

I've been working with your scripts in a MP environment.
Thanks to you I have all the pieces to begin more extensive MP testing with our tournament.

The testing I've down so far is with 3 vs 3 on a dedicated server. In terms of how the missile flys straight or properly tracks the helo looks fine. But then again 3v3 doesn't really give you much chance for lag.

The problem that has motivated me to quickly learn proper Client Server coding habits is the following:

For my debug code I use a combination of hints and sidechats to log a list of MissileIDs to keep track of the missiles fired.
The problem is every client sees a different missileID on the screen.  Now i set the local variable by using _unitecm getVariable myVariable. Isn't object variables Public? Meaning all clients would get the same value from this getVariable command?

The other concerns is the way I described my post here. But I got no answer. I've decided to ask Sickboy in other forums. He seems to have done extensive work in the MP coding area.  Looking at his code he seems to religiously use the Private command as well as the If (! local server) then {} commands as well as timely publicvarible commands. I just need to learn when and where its appropriate.

Any way I've added code to force it to run on the server to see what happens. And I only display values from object getVariable commands now.  And this week I will be doing more 2 v 2s and 3 v 3 testing and give you feedback.

Our intent is to use your code every Sunday in our 30 v 30 tournament where we are experiencing some desync and lag on occasion. So we are motivated to find the same answers as you are.

I would like to help you with your MP testing as well Mandoble.
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #7 on: 17 Apr 2007, 16:51:57 »
Lets use this as a basic case of study:

(tractorinitpos is a gamelogic placed somewhere)
Code: [Select]
// tractor_turning.sqf
_tractor = "tractor" createVehicleLocal getPos tractorinitpos;
_ang = 0;
_speed = 20;
while {_ang < 360} do
{
  _vdir = [sin(_ang), cos(_ang), 0];
  _vel = [(_vdir select 0)*_speed, (_vdir select 1)*_speed, (_vdir select 2)*_speed];
  _tractor setVectorDir _vdir;
  _tractor setVelocity _vel;
  _ang = _ang + 1; ¦nbsp;
  Sleep (0.01);
};
deleteVehicle _tractor;

Would it be MP safe ensuring all the clients and servers see the same?

ViperMaul, I understand you are just testing the ArmA stock missiles interference, right?

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #8 on: 17 Apr 2007, 16:57:56 »
"ViperMaul, I understand you are just testing the ArmA stock missiles interference, right?"

Yes. As stated above we are about to step up our MP tests this week in preparation of a big 20 v 20 test this Sunday.

EDIT: I also found this as an interesting read. To try to identify ( client or server ) a script will run on.
http://community.bistudio.com/wiki/Locality_in_Multiplayer
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #9 on: 17 Apr 2007, 18:38:31 »
For my debug code I use a combination of hints and sidechats to log a list of MissileIDs to keep track of the missiles fired.
The problem is every client sees a different missileID on the screen.  Now i set the local variable by using _unitecm getVariable myVariable. Isn't object variables Public? Meaning all clients would get the same value from this getVariable command?
No.
Variables stored into object space (using setVariable) are not public, nor published, and not even sent accross the network when you publicVariable the object itself.

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #10 on: 17 Apr 2007, 21:55:17 »
Whisper,

This is what I feared.
So what is the solution?

Code: [Select]
publicvariable myobject;
  • Will this solve my issue listed above? So that all the variables are the same
  • Will cause unnecessary lag? If yes I need to be careful about not broadcasting so much within a while do loop

Whisper, thanks so much for responding. I really didn't know how to verify this. Your answer takes me to the next step. Even though I am stuck again. That is ok. It's a learning process that I am excited about.
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #11 on: 17 Apr 2007, 22:05:57 »
I've always known it since OFP to publish a variable from a machine to all other machines and the server to the same variable. This needs to be local for it to work properly, else you have different versions of the variable flying about client to client with different value's and it will probably have different value's on each machine.

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #12 on: 18 Apr 2007, 00:03:05 »
Like I said, if on server, you do a
object1 setVariable ["object1_data", 3]
publicVariable "object1"

on a client, object1 getVariable "object1_data" should be objNull, because when you publicVariable an object, the variables attached to it are NOT passed.
You could, though, try to publicVariable the data themselves. But if it is to keep track of Mandoble missiles positions, velocity, etc... in real time in a loop, I would advise against that as it could very fast overload the network.

Now, why do you need this? To be sure that Mandoble scripts give the correct trajectories in MP to the projectiles?
In which case the problem is rather simple. I've not dug deep into Mandoble's scripts, just used them a few time (superb work, btw), but I guess he's using combinations of setPos, setVelocity, etc....
If you read the "Locality in MP" Biki article, you see that every object is local to one, and only one, PC on the game (PC can be the server ;) )
Being "local to PC P" means that decision on "what will object X do in the next frame?" is taken by P, and not any other PC in the MP game. Object can be a AI, in which case the PC where this AI is local will decide on the AI behavior (turn, run, aim here, fire, ....) then broadcast this information to all the clients and server so that all are aware of it and can render it synchronised.
Object can also be a bullet, for which trajectory must be calculated, by the PC where bullet is local, then positionnal and vector information is passed so that other PCs can render the bullet.
If a PC tries to "force the decision" for an object not local, it will not work. I guess for certain commands it can work somehow, but at the next frame, synchronization will be done again, and it will be re-synchronized with the situation on the PC where object is truely local.
As far as I've seen, each time I tried to setPos an object not local, or moveInCargo an AI not local, it never worked.

You can see the "re-sync" effect in action rather easily : make a mission with 1 player named "unit1", and 1 AI named "unit2", not grouped to player. Put 2 radio triggers, repetitive, the 1st doing "selectPlayer unit1"; the second doing "selectPlayer unit2". Save as MP mission
launch a dedicated server, then a client and connect to local dedi server. launch game. "Unit1" (player unit) is local to player's PC, of course. "Unit2" is local to the server, because it's not in player's group.
Then use radio 2 to switch to unit "unit2". By doing this, "unit2" is still "local to server", there is no transfert of locality. Try to move your character. It will move, then will quickly be switched back to its original position (re-synchronised with server's version of this unit). It's a very strange, but quite funny effect :p
I've not tested yet (but I'll do right after this post :) ), but my guess would be this :
when you make a AI unit join the player's group, this AI becomes local to player's PC (because it's in player's group), there is, this time, transfer of locality between server and PC. So, if, before doing the selectPlayer "unit2" in radio 2, I make unit2 join the player's group, then I launch the selectPlayer, I should not see any re-synchro effect occuring.

Anyway, I wouldn't bother too much about Mandoble's script. I would perhaps just check as much as I can that they are launched on PC where the guided missile/bomb/etc...  is local.


As for Sickboy's use of "private", I think it's unrelated to MP locality issues, it's more about being sure of variable's scope in his scripts, which is another tricky subject, that has appeared with ArmA SQF. I've had much more problems in ArmA scripts because of variable scope issues than because of MP locality issues, lately.
« Last Edit: 18 Apr 2007, 08:26:46 by bedges »

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #13 on: 18 Apr 2007, 00:28:03 »
I just did the selectPlayer test, and it worked as I expected :)
See attached demo mission.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: setVectorDir, setVectorUp and setVelocity in MP
« Reply #14 on: 18 Apr 2007, 00:35:41 »
Well, about the missiles the current public version has a very complex script that executes other scripts for smoke, launch, detonation, sound, endurance checks and also stores in a variable of the target the missile's object, so that the target may "know" a missile is incomming to drop flares or chaff. Well, all these is secondary, primary and mandatory commands are setVectorDir, setVectorUp and setVelocity, no setpos are used there (BTW, BIKI states setpos fails in MP).