Author Topic: Charactercontroller movement  (Read 3834 times)

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Charactercontroller movement
« on: October 06, 2013, 05:16:06 PM »
Ive been watching your vedeo tutorial for getting started, and ive decided to use the charactercontroller attach to the player object instead and write som script for that. How am i supose to link it's position trhough RFC? In the tutorial you send the destination to the gameobject the player is controlling and in that way the client that recieved the RFC can move that gameobject by itself, but if the player make alot of movements, and the "destination" can't be predicted?
Thanks in forhand :)!

Etarnalazure

  • Guest
Re: Charactercontroller movement
« Reply #1 on: October 06, 2013, 05:51:16 PM »
An easy way of doing this is simply to attach the TNAutoSync onto the player and then just add in the parameters you wish to send to the other players.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Charactercontroller movement
« Reply #2 on: October 06, 2013, 09:45:40 PM »
Easy way, yes.. but ideally you'd make a character controller that does the sync inside via RFCs.

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Charactercontroller movement
« Reply #3 on: October 07, 2013, 02:37:14 AM »
Sooo.... every time the character makes a movement, send RFC to all players in that chanel where the position is?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Charactercontroller movement
« Reply #4 on: October 07, 2013, 04:03:06 AM »
No, sync the movement vector values. For example if pressing the forward button makes the character controller set the "forward" vector to 1.0, send a sync on that vector value. If pressing "back" sets it to -1.0, same thing -- just sync that vector. This way regardless of where the control logic is coming from -- whether it's from keyboard, controller input, or from AI logic, you're synchronizing the same vector value. Then each client can do their own movement logic. The avatar's owner should also sync pos/rot periodically -- but not very frequently -- just to ensure that everyone else's simulation is correct.

In the Multi-Purpose Game Starter Kit I was doing just this -- synchronizing the movement vector values as soon as they changed by a significant margin, and the pos/rot 4 times per second (but I could easily change it to be once per second and see no ill effects).

I was also synchronizing the position and rotation when something notable happened -- such as a collision, or an explosion.

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Charactercontroller movement
« Reply #5 on: October 07, 2013, 04:10:23 AM »
Thanks alot :)! and thanks for the fast reply, but got another problem now.. Somehow the latest person who joins the game can controll both of the object meanwhile the first one can't controll anyone. I thought the "TNManager.isThisMyObject" would solve it, i'm using the "TNAutoCreate" to create the player that will say. Both objects gets the same moveDirection
  1. CharacterController controller;
  2.         public static Movement instance;
  3.         private float speed = 6.0f;
  4.         private float jumpSpeed = 8.0f;
  5.         private float Gravity = 20.0f;
  6.        
  7.        
  8.         Vector3 moveDirection = Vector3.zero;
  9.        
  10.         // Use this for initialization
  11.         void Awake(){
  12.                 controller = GetComponent<CharacterController>();
  13.                 if(TNManager.isThisMyObject){
  14.                         instance = this;
  15.                 }
  16.                
  17.         }
  18.        
  19.         void Update() {
  20.                
  21.                 if(TNManager.isThisMyObject){
  22.                         if (controller.isGrounded) {
  23.                                 // We are grounded, so recalculate
  24.                                 // move direction directly from axes
  25.                                 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0,
  26.                                                         Input.GetAxis("Vertical"));
  27.                                 moveDirection = transform.TransformDirection(moveDirection);
  28.                                 moveDirection *= speed;
  29.                                
  30.                                 if (Input.GetButton ("Jump")) {
  31.                                         moveDirection.y = jumpSpeed;
  32.                                 }
  33.                         }
  34.                         else{
  35.                                 moveDirection.y -= Gravity * Time.deltaTime;
  36.                         }
  37.                        
  38.                         if(moveDirection != Vector3.zero){
  39.                                 tno.Send(255,Target.AllSaved,moveDirection);
  40.                         }
  41.                 }
  42.                
  43.                 // Move the controller
  44.                 if(moveDirection != Vector3.zero)
  45.                         controller.Move(moveDirection * Time.deltaTime);
  46.         }
  47.         [RFC(255)]
  48.         public void updatePlayersMoveDirection(Vector3 moveDirr){
  49.                 moveDirection = moveDirr;
  50.         }
  51.  

For anyone who got the same problem so did i just solve this problem by changing the TNManager.isThisMyObject with tno.ismine
« Last Edit: October 07, 2013, 08:09:14 AM by addebooi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Charactercontroller movement
« Reply #6 on: October 08, 2013, 12:58:05 AM »
tno.isMine is what you should be checking, not TNManager.isThisMyObject. The latter can only be used on object creation -- so you can use it in Awake, but not in Update. Also, I advise you to change your Awake to Start instead.