I am working on a game where after you beat a level the player gets moved to the new start position in the same scene using transform.position. In that same function all objects except the player get destroyed and re-instantiated into a bigger level (each level gets bigger as you move on). However, sometimes the player does not move from its position even though it receives the transform.position update. The only instance I’ve been able to avoid this bug is by keep the level the same size every time it gets re-instantiated. I also ran some Debug.Log calls and noticed that when this bug occurs the player does move to the new position but then snaps back to its old position in an instant. Here’s what that output looks like:
Current Position: (-126.7, 1.1, -127.3)
UnityEngine.Debug:Log(Object)
PlayerController:Update() (at Assets/Scripts/PlayerController.cs:276)
Current Position: (-126.7, 1.6, -127.3)
UnityEngine.Debug:Log(Object)
PlayerController:Update() (at Assets/Scripts/PlayerController.cs:276)
Sent: (200.0, 2.0, 200.0)
UnityEngine.Debug:Log(Object)
ProceduralGeneration:levelBuild() (at Assets/Scripts/ProceduralGeneration.cs:47)
ProceduralGeneration:Update() (at Assets/Scripts/ProceduralGeneration.cs:38)
Current Position: (200.0, 2.0, 200.0)
UnityEngine.Debug:Log(Object)
PlayerController:Update() (at Assets/Scripts/PlayerController.cs:276)
Current Position: (-126.7, 2.6, -127.3)
UnityEngine.Debug:Log(Object)
PlayerController:Update() (at Assets/Scripts/PlayerController.cs:276)
Also to give you a general idea this is what my transform.position update looks like:
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
As the game mode scales in difficulty so does the size of the level so the starting point gets farther and farther each time.
Any assistance with this issue would be greatly appreciated.