playMaker

Author Topic: How to sync a jump command over PUN  (Read 6723 times)

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
How to sync a jump command over PUN
« on: March 10, 2014, 05:11:16 AM »
Hi everyone

I'm still a n00b when it comes to PlayMaker but i've been using it for the last couple of weeks and feel like I have a reasonable good basic understanding.

In my own test project I'm trying to do a simple task - sync the movements of player characters across Photon in a simple multiplayer scene.

I've got the basic movement and rotation sync'ing reasonably well (using Lerp2 as per several examples I downloaded), however I have a problem with jumping.

My player character is using the first person components rather than the third person components I studied in the examples. As mentioned, I had to update the rotation logic in to use Lerp2 as there were too many dropped sync calls and the rotation was very blocky.

My problem at the moment relates to jumping. Despite there being the character motor attached to my player character, sync'ing jumping appears to be very dodgy. Most of the time other characters won't jump even when they should. In my mind I've decided that it must be something to do with the lerping of the Y axis, over a short range of vertical movement, over a network that won't/can't sync every single pixel change. Therefore when the other player character jumps, I usually just see a tiny bit of vertical movement - barely enough to get off the ground.

For this reason I decided to reset the Y acid on the position vector to 0 to prevent any vertical movement being included in the position lerp, to avoid the slight movements on the Y when the character should jump.

Instead I figured I'd sync a simple bool value that is normally set to false, but when the jump button is pressed by a player it is set to true. for other characters, when the value becomes true in the variable fsm (synced) they should tell the character motor of that character to jump (set inputJump to true).

Problem is this doesn't appear to work. It looks like the first part is okay - setting the variable to true - but the part where the character motor sets inputJump to true either never gets there or has no effect.

Has anyone any advice on my approach here; am I on the right track or going way down the rabbit hole? In either case some advice/pointers would be appreciated. I've tried several variations of the sync fsm to try to get it to work but so far, no dice.

cheers!

Lee

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #1 on: March 10, 2014, 04:45:27 PM »
If it helps here's the overview of the FSM. The reason I have the return loop from the end states is that they aren't all running on every frame, so this just returns the fsm to the start ready for the next pass (that's as I understand how these things work anyway!)


Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #2 on: March 10, 2014, 05:23:44 PM »
crap I just thought, should I be RPC'ing an event (i.e. RPC a JUMP event) to observing players (i.e. everyone but me) to let them know to jump? Presumably the same logic would apply to firing a gun too?

I'm sure i'm being r-tarded here.  :-\

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to sync a jump command over PUN
« Reply #3 on: March 11, 2014, 06:27:56 AM »
Hi,

 Have you studied the Sample provided? It's very important, everything is in there to show you how to synchronize jumps and how to to RPC.

The sample can be downloaded here:
http://www.hutonggames.com/samples.php

The full help is here:
https://hutonggames.fogbugz.com/default.asp?W928

bye,

 Jean

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #4 on: March 11, 2014, 06:34:53 AM »
Hi Jean

Yeah i've always got the demo scene open, you did a great job putting that together so thanks for that. Actually the chat system (sending RPCs) is what made me think of that idea rather than my current implementation. I also see the player custom properties watch FSM although I have to admit I'm not entirely sure how that's syncing with other players.

Could you just advise in a few words the correct approach here - to jump/fire should I go the RPC route or study closer the player custom properties FSM?

Also am I even on the right track with regards to jumping? Lerping the vector3 on all the axis really didn't work for jumping, but I'm not 100% sure whether that's expected (given jump height is fairly short and therefore not a lot of Y data to lerp)  or if maybe there are some collider issues. Seems to me though that as a jump is not going to have  awhile lot of range of movement, I might expect to run in to trouble syncing this data such that other player's jumping may not be high enough to reach a ledge (or whatever) that the player has jumped upon. This is why I thought it better simply to tell the player to jump and let the character motor handle that as it would for a normal player, thus ensuring a consistent jump range (although it remains to be seen if the position information is also correctly sync'd at the time and therefore the players are jumping at exactly the right moment).

thanks for all your help on this issue and everyone else's, you've done one hell of a job here.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to sync a jump command over PUN
« Reply #5 on: March 11, 2014, 06:42:55 AM »
Cheers mate :)

Getting completly overwhelmed with the forum activity tho, but Lane is helping out now so this is good!

 I would study closer the player, but not the custom properties, it's not related, you have to study how it simply synchronized a boolean and on the other end, trigger the jump when it detec that this flag is true. BUT it only triggers the animation, not the position, this is handled with the position synching, so in this case you never miss the ledge as it's not a real jump, it's a position syncing combined with an animation synching.

Does that make sense?

bye,

 Jean

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #6 on: March 11, 2014, 06:53:46 AM »
I can only imagine the workload you are faced with running this forum and iterating PM! Glad it's not me - put it that way   :o

What you say sorta makes sense although in my demo scene my character is a simple block and has no animations attached. Perhaps what you're really indicating here is that the lerp of the Y axis in the synced position vector3 should have produced a properly sync'd position of the other character, whereas as I say with my demo all I saw was a very slight juddering and no actual lift-off. That's also why I wondered if colliders were the cause but it's difficult to know when all I have is a simple box collider on my player model (inside the parent player gameobject) and nothing else. even when it is disabled the player can jump on top of objects, leading me to believe that character controller or the fps input controller scripts are maybe adding a collider themselves (not that I could see one when inspecting the running scene).

coming back to your animation jump point, are there any watch outs with regards to me using the character motor to set the inputJump flag to true? this is different to how you've set the animation state on the character controller so i'm wondering if the two techniques aren't exactly transferrable?

thanks again  8)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to sync a jump command over PUN
« Reply #7 on: March 14, 2014, 08:41:15 AM »
Hi,

 I think you shoudl double check that you properly disable all controlling scripts on the instances that are slaved ( not "is mine"), it could be a confict here. Also, if the jump if quick and network latency is important the data stream may be too fast for the jump to be reproduced, in which case I would go for a manual override of the jump and treat it manually, using a RPC call and animating the jump perfectly, if you know the landing position , even better!

bye,

 Jean

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #8 on: March 14, 2014, 10:18:46 AM »
Hi Jean thanks for the reply

I'll double check i'm disabling everything but i'm pretty sure that it's okay there. the jump is only about a metre high for my player, so it was just a thought that maybe that wasn't enough to sync. That said I rechecked your demo and the jumping there works fine. I'm wondering now if it is something to do with me using the FPS controller where you used the 3rd Person Controller. I looked at the player char you have when the game is running and couldn't see a character collider being created, so perhaps it's because with FPS the char collider that is auto created is sticking to the collider on the floor? I dunno... kinda stuck here (no pun etc :) )

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #9 on: March 18, 2014, 07:35:38 AM »
I'm close to admitting defeat here. Haven't a clue why my char can't jump whilst your demo char can. I tried using the 3rd person controls as per your demo char but immediately ran in to really bad rotational issues (didn't get as far as checking the jump!). I think my newbieness is starting to be a real problem here.

Is there any reason a game object that contains a cube (to represent the player), another cube to crudely represent where a gun might go, and a camera, should cause such problems? There are no colliders added other than what the fps/3rd person controls add themselves (I removed them from the cubes when first created). The arena the character wanders around is a basic floor & walls test setup, with a few textures applied and a sandbox. I'm clueless why any of this should cause such issues (although at this point i think it's less a PM/PUN issue and more a basic Unity one, so this isn't really the best place to be asking...sorry)  >:(
« Last Edit: March 18, 2014, 07:37:14 AM by sibbaldl »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to sync a jump command over PUN
« Reply #10 on: March 27, 2014, 03:03:05 AM »
Hi,

 Have you been able to make some progress on this?

 -- Can you sync other Fsm variables? or is it just this jump?

bye,

 Jean

Snouto

  • Playmaker Newbie
  • *
  • Posts: 8
Re: How to sync a jump command over PUN
« Reply #11 on: May 08, 2014, 06:11:11 AM »
Hi Jean

Wow, sorry, I completely didn't see your last message until just now! I've not been able to work on the test setup for a while as real life got in the way but the basic problem remained - I could sync the movement and rotation but the jump was causing all sorts of issues. Interestingly, when I tried to sync the jump command rather than sync the jump position the player would not jump. This might have been due to some bad PM logic - i'm not sure - but i'll be getting back on this soon and with a fresh head I might be able to get somewhere. Or at least better explain the issue. I probably need to tear it all down and start from scratch, perhaps without PM first just to see if it works over PUN at all. I'll be sure to be back here the instant I hit the brick wall again!