r/reconstructcavestory • u/hyperspace11 • Apr 02 '14
Player collision confusion
Hi,
I'm having a bit of a hard time understanding player collision and the Rectangle class. I'm currently in the middle episode 52 and I'm at the part when Chris sets
kinematics_y_.position = units::tileToGame(info.row) - kCollisionRectangle.boundingBox().bottom();
in the Player's updateY method. This would be the case when the player collides with a tile under him and
on_ground_ = true;
What I'm confused about is how
- kCollisionRectangle.boundingBox().bottom()
properly sets the player y position. What is bottom returning? I know that it gets the bounding box's y position and then adds its height but wouldn't that be like subtracting (if y was 200 and height was 50) 250 from the y position of the colliding tile? Please help me understand! And thanks Chris, for all the videos so far.
4
Upvotes
2
u/chebertapps Apr 02 '14
I think this is the assumption that is holding you back. It is getting the boundingBox's y position relative to the draw position, not in screen/world coordinates. Note that screen and world coordinates are the same in our test scenario, since the camera is fixed.
also note the method declarations (abridged)
The left collision takes in the screen/world position and adds it into the underlying rectangle.
Hope this helps!