void Update() { Step(); if (!networkObject.IsServer) { if (_syncBuffer.HasKeyframes) { _syncBuffer.UpdatePlayback(Time.deltaTime); _transform.position = _syncBuffer.Position; _transform.rotation = _syncBuffer.Rotation; } } if (networkObject.IsServer) { _rigidbody.AddTorque(Vector3.forward * HorizontalInput * Agility * Time.deltaTime, ForceMode.Impulse); /* Handle Rotation */ Quaternion rotation = _rigidbody.rotation * Quaternion.Euler(0, 0, HorizontalInput * Agility * Time.deltaTime); //_rigidbody.MoveRotation(rotation); /* Handle Movement */ _rigidbody.AddForce((rotation * Vector3.up) * VerticalInput * 1000.0f * Acceleration * Time.deltaTime); if (_rigidbody.velocity.magnitude > Speed * 1000.0f) { _rigidbody.velocity = _rigidbody.velocity.normalized * Speed * 1000.0f; } } }
private void Update() { if (!hasAuthority) { if (_syncBuffer.HasKeyframes) { _syncBuffer.UpdatePlayback(Time.deltaTime); _transform.position = _syncBuffer.Position; _transform.rotation = _syncBuffer.Rotation; } } else { // movement _input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); // teleportation if (Input.GetKeyDown(KeyCode.Space)) { // send a keyframe to interpolate to before teleporting SendSyncMessage(); var newPosition = new Vector3(Random.Range(-6f, 6f), 2f, Random.Range(-6f, 6f)); _rigidbody.position = newPosition; _rigidbody.rotation = Quaternion.identity; _rigidbody.velocity = Vector3.zero; _rigidbody.angularVelocity = Vector3.zero; // and then immediately send a teleportation keyframe with 0 interpolation time SendSyncMessage(); } } }