godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.44k stars 1.52k forks source link

Fixed bug in pong demo where ball does not reset to center. #1057

Closed grimatoma closed 1 month ago

grimatoma commented 1 month ago

The initial position is set as the vector2 of Position but Position is a pointer so it updates meaning the initial position is the current position of the ball

paulloz commented 1 month ago

Vector2 is a struct, and as such is copied on assignment. So both of those lines will yield the same result:

_initialPos = Position;
_initialPos = new Vector2(Position.X, Position.Y);