Unsmooth motion of cars (476838)

Hello everybody,

I am making a car racing game. A unique problem has arisen since I have made it multiplayer and networked. The movement of the cars on Ipads isn’t smooth in case when both are in motion.

Is there a problem with the interpolation I am using with the remote cars?

Whatelse can be the problem??

try in the editor, and try without network.

Are you using the network view on rigidbody? NetworkRigidbody?

Show us the interpolation code.

Dear atrakeur,

I am not using Unity’s networking (not employing rigidbody for the moment, keeping it simple). I am using SFS 2X.


Dear Mariusz,

Here’s the interpolation code.

using UnityEngine;
using System.Collections;

public class SimpleRemoteInterpolation : MonoBehaviour {

	// Extremely simple  interpolation script
	private Vector3 desiredPos;
	private Quaternion desiredRot;
	
	private float dampingFactor = 5f;
	
	void Start() {
		desiredPos = this.transform.position;
		desiredRot = this.transform.rotation;
	}
	
	public void SetTransform(Vector3 pos, Quaternion rot, bool interpolate) {
		// If interpolation, then set the desired pos+rot - else force set (for spawning new models)
		if (interpolate) {
			desiredPos = pos;
			desiredRot = rot;
		} else {
			this.transform.position = pos;
			this.transform.rotation = rot;
		}
	}
	
	void Update () {
		
		this.transform.position = Vector3.Lerp(transform.position, desiredPos, Time.deltaTime * dampingFactor);
		this.transform.rotation = Quaternion.Slerp(transform.rotation, desiredRot, Time.deltaTime * dampingFactor);
	}
}

Sync the rigidbody instead.

This transfert position and rotation like transform, but transmit velocity and angular velocity as well.

It’s very important in objects moving fast across the network…

atrakeur: not necessarily true, there is nothing wrong with syncing the pos/rot of a rigidbody that is moving on one computer to another, as long as you make sure to make it kinematic on the receiving end.

Can there be a problem with the Smooth Camera Follow Script I am employing? Can it not be the case that my camera is not rendering the game scene smoothly? And it seems that the problem is with the cars motion? The script is derived from the one that comes with Unity which I am showing below.

/*
This camera smoothes out rotation around the y-axis and height.
Horizontal Distance to the target is always fixed.

There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.

For every of those smoothed values we calculate the wanted value and the current value.
Then we smooth it using the Lerp function.
Then we apply the smoothed values to the transform's position.
*/

// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we 
var heightDamping = 2.0;
var rotationDamping = 3.0;

// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")


function LateUpdate () {
	// Early out if we don't have a target
	if (!target)
		return;
	
	// Calculate the current rotation angles
	var wantedRotationAngle = target.eulerAngles.y;
	var wantedHeight = target.position.y + height;
		
	var currentRotationAngle = transform.eulerAngles.y;
	var currentHeight = transform.position.y;
	
	// Damp the rotation around the y-axis
	currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

	// Damp the height
	currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

	// Convert the angle into a rotation
	var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
	
	// Set the position of the camera on the x-z plane to:
	// distance meters behind the target
	transform.position = target.position;
	transform.position -= currentRotation * Vector3.forward * distance;

	// Set the height of the camera
	transform.position.y = currentHeight;
	
	// Always look at the target
	transform.LookAt (target);
}

Hi azfar, I dealt with and solved a similar problem in this thread here: http://forum.unity3d.com/threads/125084-objects-owned-by-other-players-twitch-when-moving-in-the-same-direction-as-the-player. Perhaps you’ll find the answer you need.

I should point out, I still haven’t gotten around to solving the extrapolation regime but if you’re physics is simple enough you can get away with extrapolating just with velocities.