Author Topic: Setting up and spawning a player  (Read 15040 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #15 on: May 02, 2013, 08:23:45 AM »
Why would you want that? I mean yes, you can (Target.Host), but why? In games you generally want each player to always feel responsive, so if their own character "lags" because it has to wait on the host, it would be bad.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #16 on: May 02, 2013, 09:15:41 AM »
I'd like the game to be authoritive so clients can't send bogus RFC's and teleport, spawn at different places etc.  My plan was to have the local client move themselves anyway and just lerp/move to (like everyone else sees them do) to the authorised position.  That would work, right?

Or is there a better way to prevent bogus position updates and other game events (like player 1 claiming they shot player 2)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #17 on: May 03, 2013, 08:48:36 AM »
It's better to have the host run verification logic instead. Let the client "teleport", but the host should keep an eye on the distance of movement in RFCs -- if it's too much, boot the player.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #18 on: May 03, 2013, 10:41:15 AM »
So would that would be something along the lines of:

  1. if(TNManager.isHosting) {
  2.  if(currentPosition - newPosition > 100) {
  3.       Print("This player has teleported)";
  4.        etc...
  5.    }
  6. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #19 on: May 03, 2013, 11:18:38 AM »
Yup.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #20 on: May 03, 2013, 11:25:10 AM »
Excellent. Thanks for all your help so far, I really appreciate it! I'm finally beginning to understand how this works.

So now that I have everything set up and spawning, I need a little help with movement. This is the code I'm using to sync positions:

  1.                
  2.                 if(!tno.isMine) {                              
  3.                        
  4. transform.position = Vector3.Lerp(transform.position, mTarget, Time.deltaTime * sentSpeed);    
  5.                        
  6.                         if(transform.rotation != mTargetRot) {
  7.                                 transform.rotation = Quaternion.Slerp(transform.rotation, mTargetRot, sentSpeed * Time.deltaTime);
  8.                         }                      
  9.                 }

And the end of my movement code I call the following RFC to update the position over the network:

  1.         [RFC(5)]
  2.         void OnSetTarget (Vector3 pos, Quaternion rot, float speed)
  3.         {
  4.                 mTarget = pos;
  5.                 mTargetRot = rot;
  6.                 sentSpeed = speed;
  7.         }

I've tried using Vector3.MoveTowards() and Vector3.SmoothDamp() and in every case the movement is smooth but there's quite a bit of lag now and again, especially when jumping. What would you recommend for cutting down on this as much as possible?

Side question: can I not check tno.isMine in JavaScript scripts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #21 on: May 03, 2013, 09:40:10 PM »
You must place C# scripts into the Plugins folder if you want to use them with javascript. It's the same as NGUI.

I recommend separating physics from the renderer. Renderer can smoothly follow an immediately-updated physics object.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #22 on: May 03, 2013, 10:51:06 PM »
You must place C# scripts into the Plugins folder if you want to use them with javascript. It's the same as NGUI.

I recommend separating physics from the renderer. Renderer can smoothly follow an immediately-updated physics object.

How would I separate physics from the renderer? I have a simple capsule with a character controller attached to it.  So do you mean I should have a separate object (empty GameObject?) which the position of is updated and have the capsule with the controller parented to it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #23 on: May 04, 2013, 01:13:38 PM »
Just look at what I did with the cubes from the 2nd example that comes with TNet and do the same thing. :)

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #24 on: May 04, 2013, 02:25:16 PM »
Okay great, that seems to have fixed a lot of movement issues. EDIT: In fact I don't think it did, does that technique only work on rigid bodies? My player has a character controller attached to it.

If I want clients to send data to the server (e.g. username and password) and then have the server code communicate to an external mySQL database, can I do this with a custom packet? (Explained in your tutorial (I've yet to watch it) http://www.youtube.com/watch?v=cmc_oIWmroI.)

Which server files would I edit, or is this explained in the tutorial?

Thanks for all your help thus far ArenMook! I'm looking to make a fairly large and many player world, will TNet be able to handle a lot of simultaneous connections (500+?) and a lot of AI all validated and ran through the host?
« Last Edit: May 04, 2013, 04:02:17 PM by Braveheart »

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #25 on: May 06, 2013, 10:33:51 PM »
Okay great, that seems to have fixed a lot of movement issues. EDIT: In fact I don't think it did, does that technique only work on rigid bodies? My player has a character controller attached to it.

If I want clients to send data to the server (e.g. username and password) and then have the server code communicate to an external mySQL database, can I do this with a custom packet? (Explained in your tutorial (I've yet to watch it) http://www.youtube.com/watch?v=cmc_oIWmroI.)

Which server files would I edit, or is this explained in the tutorial?

Thanks for all your help thus far ArenMook! I'm looking to make a fairly large and many player world, will TNet be able to handle a lot of simultaneous connections (500+?) and a lot of AI all validated and ran through the host?

Bump, Aren could you give me some input on communicating with mySQL via client sends request to server with information to query with mySQL? Custom packet? Can I code some mySQL connection and querying code straight into the Server.cs file(s)?

Also I'm TNManager.Creating a bullethole prefab with persistent marked true however they are not remaining in-game after all players exit, why would this be?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #26 on: May 06, 2013, 11:13:16 PM »
Unless you create your channel with the persistent flag 'true', the channel will be closed when the last player leaves.

I can't help you much with SQL. That's outside the kit's functionality. Sending a custom packet is easy, but what happens after the server receives that packet is entirely up to you.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #27 on: May 06, 2013, 11:43:33 PM »
Unless you create your channel with the persistent flag 'true', the channel will be closed when the last player leaves.

I can't help you much with SQL. That's outside the kit's functionality. Sending a custom packet is easy, but what happens after the server receives that packet is entirely up to you.

Where about do I set the channel to persistent if I'm using the standalone server?

What I'm asking though is, if I want to add in mySQL communication code, can I:

Send a custom packet with say username and password to the server; then
have inside the server code the mySQL communication code which after that executes sends a response back to the client?

Or would the mySQL code have to go outside of the server files?

Also is there an easy way to add a child object to an object that was created via TNManager.Create?
What about make another object the parent of the one you created?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting up and spawning a player
« Reply #28 on: May 07, 2013, 12:32:45 AM »
It's one of the parameters in JoinChannel function.

I recommend keeping as much in memory as you can. SQL calls are expensive and take a while to query. It would be a lot faster to keep all the usernames and associated encrypted passwords in memory, as a simple memory look up is going to be several orders of magnitude faster.

But yes, you can structure it so that your server can call SQL -- but again the SQL communication is up to you, and I can't be of much help with that.

I would not recommend parenting dynamically instantiated objects because when time comes to destroying one of them, things can get hairy.

Braveheart

  • Guest
Re: Setting up and spawning a player
« Reply #29 on: May 07, 2013, 12:55:29 AM »
In memory as in, static variables? Wouldn't those be exposed to cheaters, though?

I wanted to ask about the host authorising stuff also, my game is intended to have quite a number of players and I have the host doing all rigidbody bullet movement and hit detection also they will validate damage of these bullets too.  I plan to have the host do quite a bit in terms of validation (all SQL calls would be routed through them, AI and such like).  Is this going to cause problems with a lot of players in the game?

Also, is there any way to quickly send an RFC to only players close by? Or would I have to look for players within X distance and loop through them individually sending them the RFC's?