I'm sure the problem is me.
Here is a simple look script (from a tutorial, actually).
I'm getting inconsistent results between editor and runtime. I'm guessing its a framerate thing.
Code:
using UnityEngine;
using Mirror;
using Cinemachine;
public class PlayerCameraController : NetworkBehaviour
{
[Header("Camera")]
[SerializeField] private Vector2 maxFollowOffset = new Vector2(-1f, 6f);
[SerializeField] private Vector2 cameraVelocity = new Vector2(4f, 0.25f);
[SerializeField] private Transform playerTransform = null;
[SerializeField] private CinemachineVirtualCamera virtualCamera = null;
private Controls controls;
private Controls Controls {
get {
if (controls != null) { return controls; }
return controls = new Controls();
}
}
private CinemachineTransposer transposer;
public override void OnStartAuthority()
{
transposer = virtualCamera.GetCinemachineComponent<CinemachineTransposer>();
virtualCamera.gameObject.SetActive(true);
Controls.Player.Look.performed += ctx => Look(ctx.ReadValue<Vector2>());
enabled = true;
}
[ClientCallback]
private void OnEnable() => Controls.Enable();
[ClientCallback]
private void OnDisable() => Controls.Disable();
private void Look(Vector2 lookAxis) {
float deltaTime = Time.deltaTime;
float followOffset = Mathf.Clamp(
transposer.m_FollowOffset.y - (lookAxis.y * cameraVelocity.y * deltaTime),
maxFollowOffset.x,
maxFollowOffset.y);
transposer.m_FollowOffset.y = followOffset;
playerTransform.Rotate(0f, lookAxis.x * cameraVelocity.x * deltaTime, 0f);
}
}
The code seems right. Watching the values of Vector2 lookAxis
reveals that the numbers are slightly different coming into the function based on environment.
Is there something wrong with this code that would give different results between editor and runtime?
lookAxis
variable represent a mouse movement delta in pixels, or an analog stick displacement, or something else? \$\endgroup\$