torsdag 28 februari 2019

Cleanup and physics exploration

Today we did some cleanup of the code in the old project that we base our project on. This involved some standardizing of code style, and separating some code into smaller functions and classes.

We also started implementing different materials for the surfaces of collision.

We tried exploring how to realistically implement collision reaction. In the process, we broke the old code. Now the balls cannot bounce off surfaces at all, they land and get stuck on the plane. Figure 1 shows this behavior.

Figure 1

To aid or exploration of the subject, we came across these videos explaining collision in a context similar to ours:

https://www.youtube.com/watch?v=1IvUNya9Zf0

https://www.youtube.com/watch?v=hz_KCgV_nkw

Our next step will be to adapt and implement what is said in the videos to three dimensions and non-vertical walls.

måndag 25 februari 2019

Project Specification



Golf Course Simulation using Unity

Specification of project in DD1354 Models and Simulation 

Royal Institute of Technology KTH



Michael Mathsson  mathsso@kth.se

Anders Steen     astee@kth.se


Grade ambition: C

1 Background

Collision detection is a physical phenomenon that is very naturally part of our world. Therefore, a physical simulation that does not implement collision detection will be extremely lacking. Multiple different methods exist for simulating collisions, with varying sophistication. The geometry of an object determines the best way of detecting collisions. Spheres, e.g golf balls, are defined by a point in space and a radius. Detecting collisions between spheres simply means checking whether the points of two spheres are closer to each other than the sum of their radii.

Simulating realistic collisions does not only involve correctly detecting the collisions, but the simulation responding to the collision in a realistic manner. Objects bouncing off surfaces should have their momentum changed according to certain rules. For instance, a golf ball landing on grass will bounce in a way distinct from a golf ball landing in sand.

The interest for this kind of simulation came from lectures in the course and a collision detection project done by other students. Another source of inspiration is games such as Wii Sports Golf, which implements collision detection and reaction in a real-time gameplay setting.

The base of the project is an unfinished project by one of the group members which implements simple circle-plane hit detection and pseudo-physics for collisions.


2 Problem

Implementing collision detection between a sphere and a plane or mesh, as well as simulating realistic collision reaction is the initial problem. This means changing an object’s momentum according to attack angle, velocity and material of the colliding objects. Achieving further realism is the secondary problem. Implementing wind simulation and creating a realistic golf course environment are included in this secondary problem.


Figure 1

3 Implementation

The first implementation goal is to create working collision detection and reaction between a sphere and a plane and mesh. This will be done in Unity using a combination of Unity’s built-in objects and our own collision detection methods. As few Unity assets as possible will be used, they are only meant to provide visuals for the simulation.

After the implementation of the core features is complete, more variation will be introduced. This will be in the form of different materials of colliding objects creating different collision reactions. Air resistance and wind changing the momentum of golf balls will also be implemented if time permits.
The final result will be a real-time simulation in Unity that handles collision detection and reaction in a golf course setting. The realism of the simulation will depend on how difficult the core features turn out to be to implement. See Figure 1 for a conceptual picture of the best-case end result.

3.1 Specification ideas

Our planned features, in descending order of relevance and priority.

  • Collision detection
    • Sphere to plane 
    • Sphere to sphere 
    • Sphere to mesh 
  • Realistic bouncing 
    • Correct angle 
    • Realistic conservation of energy 
  • Collision with different materials 
    • Bounciness varying based on terrain 
    • Friction when rolling 
    • Materials: 
      • Grass 
        • Rough 
        • Green 
        • Fairway 
      • Sand 
      • Water 
  • Wind simulation 
    • Air resistance 
      • Specific to the shape of a golf ball
    • Affecting golf balls 
    • Calculated using rigorous methods such as Navier-Stokes equations
  • Aesthetically pleasing environment 

4 Risks and challenges

Below is a table describing potential risks and challenges specific to this project.

DescriptionContingency plan
Finding accurate physics equationsIf we can’t figure out how it works in reality we can complement it with pseudo-physics.
Combining Unity assets with our codeEither use more of Unity’s assets or make our own assets and settle for an ugly simulation and more work required.
Some physical phenomenon are difficult to implementThose difficult features can be discarded from the project, be simplified or possibly included through unity assets.

5 References

  1. Project blog: https://modsimspheres.blogspot.com/
  2. Collision detection in course lecture slides: https://www.kth.se/social/files/5c5c028f56be5b3639e2695f/DD1354%20Particle%20Systems%20and%20Collision%20Detection%202019.pdf
  3. Descriptions of collision reaction: 
    1. https://en.wikipedia.org/wiki/Inelastic_collision
    2. https://en.wikipedia.org/wiki/Momentum#Conservation
  4. Wii Sports Golf example: https://www.youtube.com/watch?v=-Mm7xoaTzdM