Rigid body kick over network (DEADLINE)
I have a game with a ball. Players can join in and everything looks fine and their position sync perfectly. My problem is that when the client player tries to kick the ball with the kick script the ball doesn't move, like it doesn't register the add force. The client player can only slightly push the ball, but it feels extremely heavy.
I'm a student and this is my first time making a networked game so any help is very much appreciated. I'm using UNET so I'm just using the standard network components.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class TriggerKick : NetworkBehaviour{
Rigidbody rb;
GameObject ball;
public float kickThrust;
public float dirKick;
public NetworkIdentity BallnetworkIdentity;
public KicktriggerChecker kickTriggerChecker;
//public NetworkTransform ballNetworkTransform;
// Use this for initialization
void Start()
{
kickTriggerChecker.BallInRange = false;
ball = GameObject.FindGameObjectWithTag("Ball");
rb = ball.GetComponent<Rigidbody>();
BallnetworkIdentity = ball.GetComponent<NetworkIdentity>();
//ballNetworkTransform = ball.GetComponent<NetworkTransform>();
Debug.Log("Player started is local");
}
void Update()
{
//first propper Kick interation
if (kickTriggerChecker.BallInRange && Input.GetKey(KeyCode.Space) && Input.GetButtonDown("Fire1"))
{
Transmitkick(Vector3.up);
}
else if (kickTriggerChecker.BallInRange && Input.GetKey(KeyCode.LeftShift) && Input.GetButtonDown("Fire1"))
{
Transmitkick(Vector3.down);
}
else if (kickTriggerChecker.BallInRange && Input.GetKey(KeyCode.D) && Input.GetButtonDown("Fire1"))
{
Transmitkick(Vector3.right);
}
else if (kickTriggerChecker.BallInRange && Input.GetKey(KeyCode.A) && Input.GetButtonDown("Fire1"))
{
Transmitkick(Vector3.left);
}
else if (kickTriggerChecker.BallInRange && Input.GetButtonDown("Fire1"))
{
Transmitkick(Vector3.zero);
}
}
[Client]
void Transmitkick (Vector3 direction)
{
Debug.Log("local player is about transmitting kick");
if(isLocalPlayer)
{
Debug.Log("local player is transmitting kick");
BallnetworkIdentity.localPlayerAuthority = true;
//ballNetworkTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncNone;
CmdRecieveTransmission (direction);
kick (direction);
return;
}
}
[Command]
void CmdRecieveTransmission (Vector3 direction)
{
if(isLocalPlayer)
{
Debug.Log("local player is recieving local kick");
return;
}
Debug.Log("player is recieving none local kick");
BallnetworkIdentity.localPlayerAuthority = false;
//ballNetworkTransform.transformSyncMode = NetworkTransform.TransformSyncMode.SyncRigidbody3D;
kick(direction);
}
void kick (Vector3 direction)
{
//Debug.Log("kick" + direction);
rb.AddForce(transform.forward * kickThrust * Time.deltaTime, ForceMode.Impulse);
rb.AddForce(direction * dirKick * Time.deltaTime, ForceMode.Impulse);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612055319im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding Force over network 0 Answers
Networked nonplayer objects only effected by the client hosting the server? 0 Answers
[UNET] Network Transform doesnt work for the host. On Client it works seemless. 0 Answers
[uNET] Instantiated gameobjects not syncing for new clients 1 Answer
[PUN] All players control one object 0 Answers