- Home /
Client-side smoothing - example script trouble!
Hi there,
I have an application set up where I can connect multiple instances over a local network. At the moment I am just moving a box, whilst I figuring out how to get client-side smoothing working.
I have the script from the Unity networking examples, which looks like it is working. The only trouble is that the boxes (that the client doesn't own) are having their position set to 0,0,0 every frame/update/whatever.
The only time someone else's box is in the correct place is when it is moving, and even then it flickers between that position and the world origin. The prefab I am spawning has a starting transform position of 0,0,0 and is placed in a specific location by the Network.Instantiate() function when the client connects.
I thought the problem could have something to do with these 2 lines:
if (stream.isWriting)
{
*Vector3 pos = transform.localPosition;* // this one
Quaternion rot = transform.localRotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
// When receiving, buffer the information
else
{
// Receive latest state information
*Vector3 pos = Vector3.zero;* // and this one
Quaternion rot = Quaternion.identity;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
but neither broadcasting the world position nor initialising the recieving vector differently made any difference, so the reason the box is being set to the origin isn't that.
When I change the box prefab's NetworkView component to Unreliable the box flickers regardless of user input.
In my mind I think that the client is, for some reason, resetting the prefab to its original transform position unless it gets sent where to put it.
I find this strange as without the smoothing script, my boxes do not flicker although they do have jerky movement because of lag.
Does anyone have any suggestions? Thanks,
Simon.
Even changing the original transform position of the prefab doesn't stop it resetting to (0,0,0), so I really have no idea where that value is co$$anonymous$$g from!
I don't think OnSerializeNetworkView() is ever being called, as the script only ever executes the extrapolate bit. I guess due to m_BufferedState[0] never being assigned to, its position is read as 0,0,0
From what I can see online, this could be due to invalid NetworkViewIDs?
O$$anonymous$$, OnSerializeNetworkView runs when my box's NetworkView observes the NetworkInterpolateTransform script ins$$anonymous$$d of the transform. I know this because I have a debug.log which prints when the function is executed.
The problem now is that the box isn't moving in the other windows... :/ I've tried making another NetworkView observing the transform component, but no joy :(
Answer by shwhjw · Nov 09, 2011 at 10:18 PM
SOLVED!
Well, this was the most GODAWFUL, STUPID bug I have ever come across, and I've had a years' worth of experience with UDK, which says a lot!
Deary me, where to start?
In order to see what was happening in the built exe file, I created a GUIText object to display debug strings. I added a Start() function to the NetworkInterpolateTransform script to find the object in the scene and save it in a variable.
void Start()
{
debugText = (GUIText)GUIText.FindObjectOfType(typeof(GUIText));
if (debugText != null)
debugText.text = "Yay I have been found!";
}
logical enough, right?
With the script like this, the boxes not belonging to the client would stay fixed at 0,0,0 and OnSerializeNetworkView would only have run the once.
BUT if you change void Start() to void Awake() , everything starts running dandy!
This smoothing took me all of 8 hours to implement, WAY more than it should have.
Does anyone have an explanation as to why assigning the debugText object in Awake() rather than Start() would make any difference?
Today was a long day ;_;
Simon!
Sorry, but I didn't understand how you solved the problem. I have the same problem, but I don't find the solution to solve it.
Any suggestion??? thank you
Your answer
Follow this Question
Related Questions
Since switching to using offline & online scenes in the NetworkManager, Clients will not sync (UNET) 0 Answers
[Command] not sending to server? 1 Answer
Objects instantiated by the host show on all clients but client objects don't show on host. 0 Answers
Dedicated Server In Seperate Project 2 Answers
I don't know difference between interpolation and non-interpolation 0 Answers