Author Topic: Slope Physics Tutorial Part II  (Read 2484 times)

0 Members and 1 Guest are viewing this topic.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Slope Physics Tutorial Part II
« on: April 07, 2011, 04:40:35 pm »
Slope Physics Tutorial II-Adapted from Builderboy’s method in Chainfire Pinball Library.
First, let us remind ourselves of a few basic vector operations…

Think of it as if you are following a path. These two vectors, when you add them, will take you to the same place that vector C would take you. Hence, they are equal.
Now, how do we add vectors? Easy; if you keep them in component form Ax+Bx= Cx and Ay+By=Cy
Now, let’s take another look at our slope diagram. This time, let’s give the object some starting velocity. In this method of slope physics, we will only apply the physics if a collision is detected. In order to roll, the ball will have to collide with the slope every frame, and every frame the velocity will be modified appropriately.

In the diagram, the velocity is taking the object into the slope. We want to modify the velocity so that it is pointing in the right direction—we want the velocity to be transformed to become Vf. How can we do this? Note that adding the original  velocity and the vector labeled Nf will give us Vf. So now all we need to do is find Nf
Now we will use another type of vector math called the dot product. A dot B is defined as Ax* Bx+ Ay* By. The dot product also has another convenient property:

The || signs mean the magnitude of the vector; its linear length. Use the Pythagorean theorem to get it.
Now, more importantly, we can use this along with a little bit of trig to figure out what N f is…If we move the normal vector over to where N f is…

Remember that N f and the original normal vector have the same direction. So, now that we have the magnitude of N f, we can divide it by the magnitude of the original normal vector to get the ratio of their magnitudes. Then we can multiply that by their x and y components to get the components of N f:
Nfx= Nx*| Nf|//|N|
Nfy= Ny*| Nf|//|N|
And now add these to our velocity components to get our final new velocity. Happy coding 


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Slope Physics Tutorial Part II
« Reply #1 on: June 14, 2011, 02:47:43 pm »
Split into its own topic, because of the tutorial sections limitations only fetching the first post of a topic.