First i want to apologize that my English isn’t good, so i just go straight to the problem.
The ball is spawned with a BallSpawner and has registered as spawnable in Network Manager.
Say the ball original position is on 0,0,0.
From the server side i can pick, move and throw the ball just fine.
If i pick the ball from the client and move, the ball will started glitching (looks like it tries to lerp back to 0,0,0), and if i throw it the ball will just lerp back to 0,0,0.
What i’m trying to do is to get the client to be able to pick and throw the ball normally like the server.
I also provide the ball’s NetworkIdentity and NetworkTransform setting in the attachment.
Thanks.
Here’s the Ball script.
using UnityEngine;
using UnityEngine.Networking;
public class Ball : NetworkBehaviour, IPickupable, IThrowable
{
public int itemScore = 1;
void OnCollisionEnter(Collision other)
{
IScoreable scoreable = other.gameObject.GetComponent<IScoreable>();
if (scoreable != null)
{
scoreable.Score(itemScore);
}
}
public void Pickup(){}
public void Throw(){}
}
Here’s the pick method.
void Pick()
{
if (!isLocalPlayer)
return;
if (!carrying && Input.GetButtonDown(grabInput))
{
Collider[] hitColliders = Physics.OverlapSphere(pickupCenter.transform.position, radius);
int i = 0;
while (i < hitColliders.Length)
{
IPickupable pickupable = hitColliders[i].GetComponent<IPickupable>();
GameObject pickedUpObject = hitColliders[i].transform.gameObject;
if (pickupable != null)
{
float distance = Vector3.Distance(pickedUpObject.transform.position, transform.position);
float lowestDist = Mathf.Infinity;
if (distance < lowestDist)
{
lowestDist = distance;
closestGameObject = pickedUpObject;
}
carrying = true;
carriedGO = closestGameObject;
carriedGO.GetComponent<Rigidbody>().isKinematic = true;
carriedGO.GetComponent<Collider>().isTrigger = true;
}
i++;
}
}
}
And this is the spawner script.
using UnityEngine;
using UnityEngine.Networking;
public class BallSpawner : NetworkBehaviour
{
public GameObject ballObject;
void Start()
{
CmdSpawn();
}
[Command]
void CmdSpawn()
{
GameObject instance = Instantiate(ballObject, transform.position, transform.rotation) as GameObject;
NetworkServer.Spawn(instance);
}
}