Maximizing Viewport changes game behavior
Ok so here's a weird one. When I run my game in the editor without the game viewport maximized it behaves as expected. Then when I maximize the viewport "OnTriggerStay2D" stops firing. The game can be running in play mode, working fine, then without stopping I can maximize the viewport and I stop getting those triggers.
The game window doesn't change size, it's 1334x750 either way, it just gets more padding around it when maximized.
It doesn't seem like maximizing the viewport should have any effect whatsoever on the running game but it clearly does. I have no clue how to even debug something like this.
void OnTriggerStay2D(Collider2D other) {
//Debug.Log (other.gameObject.name);
//drawDebugRect (other.collider2D.bounds.min, other.collider2D.bounds.max);
//If the drill trigger is in the block call reduce health
if (other.gameObject.CompareTag("Drill") ) {
//ADDED TO CHECK THIS BUG ONLY
Debug.Log (Time.time);
//OrientedBlock block = transform.parent.gameObject.GetComponent<OrientedBlock>();
x = Mathf.FloorToInt(myTransform.localPosition.x);
y = Mathf.FloorToInt(-myTransform.localPosition.y);
float damage = ((Drill)other.gameObject.GetComponent("Drill")).damagePerSecond * Time.deltaTime;
health = levelManager.reduceBlockHealth (x,y,damage);
}
}
It the Debug.Log statment stops outputing to the console in maximized but outputs just fine when not maximized.
Answer by waruban · Dec 05, 2019 at 11:46 PM
@ AlexEvangelou Same issue 2019... Anyone ???,same issue... 2019. I would appreciate if someone can share any feedback on this .
Answer by jamesjac · Feb 16, 2021 at 04:50 PM
same thing happened to me when I was adding force to an object, when I have the game window be a small window in the corner it behaves differently from when I maximize it. What seems to fix it is multiplying the values by Time.deltaTime as you can see here:
Vector3 ammont = new Vector3(0, 5000, 0);
GetComponent<Rigidbody>().AddForce(ammont * Time.deltaTime);
This fixed it and I don't know why but I think it has something to do with fps.
I know its 6 years late, but I hope your still making games.
Your answer
Follow this Question
Related Questions
camera viewport from rect to triangle 0 Answers
Car "bugs" through ground 0 Answers
Collisions happening though disabled in matrix 2 Answers
Physics Movement without Physics Reactions 1 Answer
Toggle Ignore collision on button press 0 Answers