ucsb-cs56-projects / cs56-games-alva

1 stars 2 forks source link

Refactor the physics engine #3

Open steve-fields opened 7 years ago

steve-fields commented 7 years ago

The physics engine currently works, but upon adding more things, the machine will start running slow. Here is how it currently works:

  1. Begin looping through entities
  2. Get the location and dimensions of the entity
  3. Now loop through every tile.
  4. Do the entity interesect top and bottom? Move the entity out and give it ground status
  5. Do the entity interesect side to side? Move the entity out on the side
  6. Now loop to see if it collides with other entities (ie boxes)
  7. Check the type of entity and handle collision as needed

This is REALLY inefficient. It works well because it checks everything, but for a platformer, this level of collision detection is over the top. I recommend looking into AABB, Axis Aligned Bouinding Box. Axis Aligned Bounding Box works by checking only the things around the entity. It then gets the depth in the X and Y direction, checking if it has actually collided, as well as seeing how deep in each direction it has collided. Which ever depth is more shallow, you negate and push it out. This method works well and every thing in this game is easily represented as an axis aligned bounding box.

steve-fields commented 7 years ago

F17 OK (500 pts)

steve-fields commented 6 years ago

W18 OK (500 pts)

steve-fields commented 6 years ago

Note to next mentor: This is not an easy project, it's very math intensive, leave for very ambitious group