1 / 64

Lecture 6

Lecture 6. Announcements. Next week will be great!. Three major things are happening next week: Zynga guest lecture Your game pitches (more details later) Christina Paxson. Feedback for M 1. Some of you had stacking shapes The stack probably exploded eventually

binh
Download Presentation

Lecture 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 6 Announcements

  2. Next week will be great! • Three major things are happening next week: • Zyngaguest lecture • Your game pitches (more details later) • Christina Paxson

  3. Feedback for M 1 • Some of you had stacking shapes • The stack probably exploded eventually • Don’t worry, stacking boxes is hard to do properly • This week’s lecture will help but not alleviate the problem

  4. Feedback for M 1 • Sometimes shapes would settle overlapping other shapes • Two possible causes: • Not translating enough • Doing collision response before integration, hence drawing before translating

  5. Announcements Questions?

  6. Lecture 6 Physics II

  7. M1 Collision Response • You obtained MTV in M1, how did you use it? • Move things out of collision • Apply some impulse along MTV • It probably worked most of the time, or only if you modeled specific behavior • Other times the response is weird

  8. Controlling Impulse voidonCollide(Collision col) { Shape o1 = col.shape1; Shape o2 = col.shape2; Vec2fmtv = col.mtv; o1.move(mtv.smult(0.5f)); o2.move(mtv.smult(-0.5f)); //code to calculate impulse o1.applyImpulse(imp1); o2.applyImpulse(imp2); } • Want more realistic collisions • Two things to do: • Support a range of collision behavior • Determine the physically correct collision result • Also need to be able to code it

  9. Restitution • Property of physical entities • Value between 0 and 1 • 0 is perfectly inelastic, 1 is perfectly elastic, etc. • The coefficient of restitution (COR) between two entities is the geometric mean of their restitutions:

  10. Correct Collisions • How do we find the physically correct collision response? • i.e. given and , what are and ? • Use physical definition of the COR:

  11. Translation to Code • Once we determine what the final velocities of the objects should, how do we apply this? • Impulse or velocity setting? • Setting velocity affects other collision response calculations

  12. Translation to Code • We determined what the final velocities of the objects should, how do we apply this? • Impulse > velocity setting • Setting velocity affects other collision response calculations

  13. Translation to Code • We determined what the final velocities of the objects should, how do we apply this? • Impulse > velocity setting • Setting velocity affects other collision response calculations

  14. Translation to Code • We determined the final velocities of objects, what do we do with it? • Impulse > velocity setting • Setting velocity affects other collision response calculations • Recall the definition of the impulse: • We really want the difference of final and initial velocity

  15. Final Velocities • Conservation of momentum: • The COR equationcan be rewritten as • So conservation of momentum becomes

  16. Final Velocities • Solving for : • Similarly for (reverse and basically):

  17. Velocity Difference • The velocity differences are:

  18. Final Impulse • So the impulse you want to apply is: • You can see that they are equal and opposite, as we would expect

  19. Static Shapes • If object is static, you can show that the equations in the last slide reduces to • Vice-versa if object is static • You should special case this

  20. Note about Velocity • Note that all velocities in these equations are for the one-dimensional case • But your 2D engine is 2D! • Velocity only changes in the direction of the MTV • So the ’s and ’s in the equations are the projection of velocity onto the MTV

  21. Putting it all together Physically correct collision response: • Calculate COR with the restitutions of the shapes • Project velocities onto MTV • Apply impulse formula to calculate impulses • Apply corresponding impulse to each shape

  22. Physics II Questions?

  23. Lecture 6 Raycasting

  24. What is raycasting? • Determine the first object that a ray hits • A ray is like a ray of light, has a source and direction and goes on forever • It’s like a camera (or eye)

  25. Raycasting Uses • When would we need to raycast? • Hitscan weapons • Line of sight for AI • Area of effect • Rendering

  26. The Ray • A ray is a point (source) and a direction • Point on ray given by: • is the source point • is the direction • This must be normalized! • is a scalar value (length)

  27. Basics • Raycasting boils down to finding the intersection of a ray and shapes • Kind of like collision detection all over again • You want the point of collision as well

  28. Ray-Circle • If the point is outside • Project center onto ray • Check if the projection is positive and the point is within the circle • Point of intersection:

  29. Ray-Circle • If the point is outside • Project center onto ray • Check if the projection is positive and the point is within the circle • Point of intersection?

  30. Ray-Circle • If the point is outside • Project center onto ray • Check if the projection is positive and the point is within the circle • Point of intersection?

  31. Ray-Circle • If the source point is inside the circle • Do the same thing as if outside, but: • Now is allowed to be negative

  32. Ray-Polygon/AAB • A polygon/AAB is composed of edges • We can check for intersection of ray by checking for intersection of all edges • There is no shortcut for AABs this time

  33. Ray-Edge • Edge is defined by two end points, and • We need some other vectors: • is direction of the segment (normalized) • is the perpendicular to the segment (normalized)

  34. Ray-Edge • Firstly, determine if the segment straddles the ray • Use cross products • and must be of opposite sign • Therefore no intersection if

  35. Ray-Edge • Secondly, determine if the two lines intersect • Point of intersection • Solve for • must be nonnegative!

  36. Ray-Edge • Because lies on the segment • So plugging in:

  37. Ray-Polygon • Intersect the ray with all the edges of the polygon • Ray intersects polygon if it intersects at least 1 edge • Keep track of the point that is closest to the source (the lowest value of )

  38. Putting it all together Raycasting: • Intersect ray with every shape in the world • For circles, use the circle-ray algorithm in the slides • For polygons, intersect each edge and use the closest • Keep track of closest intersection point from the source as well as the corresponding shape

  39. Raycasting Questions?

  40. Lecture 6 Final Project Overview

  41. Overview • Can be any 2D game and engine • You can work in groups if you want • Each person is responsible for 10 “points” worth of new engine features • More members in a group means more engine features • More details in the final project handout

  42. Timeline • 4 main parts: • Week 1: Idea • Week 2: Form groups and get approved • Week 3: Design • Weeks 4-8: Code, playtest, polish, present

  43. Week 1: Idea • A ½ to 1 page document • Describe basic gameplay idea • How is your game fun? • Describe engine feature(s) you plan on implementing • Give a 60-second “elevator pitch” of your game in class

  44. Week 2: Groups • Form a group (or decide to work alone) • Finalize game and engine features • Each group must meet with a TA to present the following: • A more polished idea of the game • Breakdown of member responsibilities for engine

  45. Week 3: Design • Research new engine features • Design the engine and game • Exact breakdown of member responsibilities • Choose someone’s engine to use or integrate engines • For groups of 3 or more • Explain how you will use version control

  46. Weeks 4-8 • Week 4: • Engine should be mostly done • Game exists • Week 5: • Engine should be done • Game is playable • 5 playtests per member from people not in CS195n

  47. Weeks 4-8 • Week 6: • Game should be mostly done • 5 more playtests per member from outsiders • Week 7: • Game should be done • 5 playtests per member • Powerpoint slideshow for postmortem presentation

  48. Weeks 4-8 • Week 8: • Polish up your game, bug fixes, etc • Create an executable and put it in /contrib • Make a video demo of your game from gameplay footage • It is now December 19th • And then you’re done!

  49. Final Project Overview Questions?

  50. Lecture 6 Tips for M II

More Related