I’m currently using the CharacterMotor script, to control movement and if I pause and then unpause while moving forward or jumping it results in either the character falling really fast or worse:
transform.positionWithLocalOffset assign attempt for 'Player' is not valid. Input positionWithLocalOffset is { NaN, -28.434168, NaN }.
The script gets disabled on pause and then re-enabled on resume via my pause script which is:
void Awake() {
player = GameObject.FindWithTag ("Player").GetComponent<CharacterMotor> ();
playerController = GameObject.FindWithTag("Player").GetComponent<CharacterController();
}
void PauseGame() {
isPause = !isPause;
if(isPause){
player.enabled = false;
playerController.enabled = false;
Time.timeScale = 0;
}
else{
Time.timeScale = 1;
player.enabled = true;
playerController.enabled = true;
}
}
I’ve checked and they definitely get disabled and re-enabled. I’m assuming it is coming from the way CharacterMotor calculates velocity:
movement.velocity = (tr.position - lastPosition) / Time.deltaTime;
which must be then trying to divide by zero. What can I do to avoid this problem?
edit: for now i have set Time.timeScale = 0.001; which seems to work is there a better way to tackle this problem, or will this be fine?
Thanks,
Dan