Coding the detectCollisions method: Part 2
Add the following code after the highlighted comment. Notice the first line of code is an if
statement that checks for a collision between the current GameObject
and the current player collider from the ArrayList
of the player's detailed colliders.
// More code here next if (RectF.intersects(testedTransform .getCollider(), playerColliders.get(i))) { // React to the collision based on // body part and object type switch (go.getTag() + " with " + "" + i) { // Test feet first to avoid the // player sinking in to a tile // and unnecessarily triggering // right and left as well case "Movable Platform with 0":// Feet playersPlayerTransform.grounded(); playersLocation.y = (testedTransform.getLocation().y) - ...
Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.