Question by
TDuffin · Aug 05, 2021 at 10:18 PM ·
movementinputtimemovement scripttime.deltatime
movement speed still changes with FPS; Despite using Time.deltaTime (And GetAxisRaw)!
void Update()
{
float xInput = Input.GetAxisRaw("Horizontal");
float zInput = Input.GetAxisRaw("Vertical");
Vector3 TargetDir = new Vector3(xInput, 0, zInput).normalized;
if (TargetDir != Vector3.zero) {
RB.rotation = Quaternion.LookRotation(TargetDir); }
RB.velocity = (TargetDir * Speed * Time.deltaTime);
//print(RB.velocity.magnitude);
Camera.transform.position = RB.position - CameraRelPosition;
}
The code above works fine, but I've noticed that the speed in the final build vs inspector is still wildly different even though Time.deltaTime should scale the movement speed with the framerate of my game. I'm also noticing that mousing over Unity's inspector elements visibly changes the speed of the character, and inspector GUI widgets that have no impact on the main game loop are causing skips in movement.
Any idea what I'm doing wrong here?
Comment
dir * speed * deltaTime
is not a equation for velocity, partner; dir * speed
is.