"Input positionWithLocalOffset is { NaN, -Infinity, NaN }". The kicker? The input has no NaNs.

Hi, I’m trying to adjust my custom timedelta (timedelta * (the velocity vector’s magnitude + 1)) before applying it to the same velocity vector going into a character controller. The faster you move, the slower time goes. Despite the input being fine, unity is showing NaN errors.



velocity = (0.0, -9.8, 0.0). delta = 0.005328088. velocity*delta = (0.0, -0.1, 0.0)
PlayerRunner:Update() (at Assets/PlayerRunner.cs:142)


transform.positionWithLocalOffset assign attempt for ‘Player’ is not valid. Input positionWithLocalOffset is { NaN, -Infinity, NaN }.
PlayerRunner:Update() (at Assets/PlayerRunner.cs:148)


Create the custom timedelta:

       newdelta = Time.deltaTime / ((player.velocity.magnitude * .5F) + 1F);

Test and then apply the timedelta:

		Vector3 deltaVelocity = velocity * delta;
		Debug.Log ("velocity = " + velocity + ". delta = " + delta + ". velocity*delta = " + deltaVelocity);
		if (float.IsNaN (deltaVelocity.x) || float.IsNaN (deltaVelocity.y) || float.IsNaN (deltaVelocity.z))
			deltaVelocity = velocity * Time.deltaTime;
			Debug.Log ("BAD TIMEDELTA!");
		controller.Move(deltaVelocity);	// Using char controller collisions

The NaN errors only appear if I multiply the original timedelta; removing the multiplication results in clean code.

I’ve been stuck on this for while and can’t find anything useful, please help? This is a vital component, I cannot test the game without it.

I suspect you are dividing by zero somewhere.

Setting Time.timeScale to 0 will give you a Time.deltaTime of 0. Check for anywhere you are dividing by delta time and try just adding if (Time.timeScale > 0) to stop it from recalculating while paused.