I’m making a small RPG, this got an Offline and an Online mode. In Offline, the player walks around perfectly with an Orbit Camera around him. The same should work in Online, (Online Player got Network Transform and all that stuff added to it). The problem is that when I host a server and start to walk around, the character only walks in the directions of the world, North + East + West + South. The camera is orbiting, but the player will always go North on W, South and S, West on A, and East on D. The character Im using is currently the Unity 3D character Ethan.
This is the code for the orbital camera:
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Controller/Mouse Orbit with zoom")]
public class CameraController : MonoBehaviour
{
public Transform target;
[SerializeField]
public float distance;
public float xSpeed;
public float ySpeed;
public float yMinLimit;
public float yMaxLimit;
public float distanceMin;
public float distanceMax;
private Rigidbody rBody;
float x = 0.0f;
float y = 0.0f;
void Start()
{
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
rBody = GetComponent<Rigidbody>();
if(rBody != null)
{
rBody.freezeRotation = true;
}
}
void LateUpdate()
{
if(target)
{
x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation = Quaternion.Euler(y, x, 0);
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
RaycastHit hit;
if (Physics.Linecast (target.position, transform.position, out hit))
{
distance -= hit.distance;
}
Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360f)
{
angle += 360f;
}
if (angle > 360f)
{
angle -= 360f;
}
return Mathf.Clamp(angle, min, max);
}
}
Is it an other way of doing this in Online? Have I missed something? What can I improve?
I would love fast awnsers! <3