Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hey all, still working to incorporate more physics simulation into my game (mentioned HERE). Now having the ball successfully and quite realistically bouncing a surface it hits, I wanted to make the ball spin off.

Now this seemed simple enough, I would calculate the rotation speed for the ball every time-tick and then rotate the ball by that much degrees upon drawing.

I knew that the speed of rotation would depend, upon impact, on:

  1. Initial Speed of the ball hitting the surface (magnitude of ball velocity vector)
  2. Friction co-efficient of ball & surface (constants for simulation)
  3. Angle between ball impact velocity vector and the surface normal (approximated by dot vector value of impact and exit velocity vectors. 1 meaning high spin, -1 meaning no spin, and everything else relatively in between)

so, multiplying all of the above together, and making sure they were then transformed to the range 0-1, and multiplied by Max rotation speed, the ball seemed to respond in rotation speed as was expected. Except for one thing, it was always rotating clock-wise (because of positive values)

So my question is this:

  1. What do you think of my method? I know it is not the most accurate, but it is good enough for simple simulation. Any easier ones?
  2. If this method is fine, then what am I missing? How should I know when ball should rotate clock/anti-clock wise?

thanks for any comments

share|improve this question

3 Answers

up vote 2 down vote accepted

Your method is nice, because it's very simple. One thing you might need is dependency on previous spin on the ball, which you do not take into account. The spinning ball represents rotational energy, so a realistic simulation would probably have to conserve it along with the other energies.

However, if the ball is not rotating upon impact, I can't imagine a situation in which it begins rotation against the direction of the incident angle. That is, "clockwise" or "counterclockwise" should be relative to whichever side of the normal the incident angle is.

I think simply multiplying the result by the original x-direction vector (+1 if traveling left to right, -1 if traveling right to left) should do it.

Edit: You can use the cross-product for this. Incident cross normal provides a vector in the Z direction only (if we are on the 2D x-y plane). Look at the z-element: if it is positive, the ball's approach should cause it to spin clockwise. If it is negative, the ball should spin counterclockwise.

share|improve this answer
Hey eli Firstly, I am taking into consideration the original spin of the ball, just forgot to mention it in my post Secondly, I don't think that the x-direction system would work. I tried that, but if the ball hits the surface from below going left, the x vector would be -1, it would mean counter-clockwise rotation, while in reality it should be rotating clock-wise – codemonkey Aug 10 '10 at 11:18
How do you take into account the original spin of the ball? If it is rotating very fast, it might launch itself away in a totally different direction. The problem with dot-product in your case is that it uses the cosine (an even function). You need something else to set the sign of the relationship between your vectors (incident and normal). You can use a cross-product (vector product) for this purpose. I have edited my answer to include a cross-product method. – eli Aug 10 '10 at 17:40
re-reading the answer after the edit i like it. Tried it out and it worked quite fine. Regarding original spin, i was only talking about making the rotation change gradual... as for original spin affecting exit vector, well, thats my next step :) – codemonkey Aug 10 '10 at 20:12
Ouch, the edit was one of the 3 different solutions I suggested, and I explained why you had to do it (dot only gives magnitude, not direction of angle). Alas, should be more concise I guess. – Kaj Aug 11 '10 at 4:43
sorry for that kaj, it slipped me... no offense intended :) – codemonkey Aug 11 '10 at 11:27

Ókay, this might sound stupid but you're not using the dot-product of the ball vector and the surface normal and just doing an arccos to calculate the angle are you? Because then the angle would be positive whether it was positive (up to 90 degrees) or negative (ditto) as cosine is symmetrical around 0.
If this is the case then instead of using the normal of the plane, use the plane direction itself and subtract 90 degrees from the angle, so 0 to 180 would become -90 to +90 degrees (or -half PI to +half PI if you're radially inclined).

share|improve this answer
Well, consider this case: x+ve is right, y+ive is down; Surface vector S=(1,0); we have two impact velocity vectors V1=(3,4) hitting from above, should rotate ball clock-wise & V2=(3,-4) hitting from below, should rotate ball anti-clock-wise. Now normals for both vectors would be (3/5,4/5) & (3/5,-4/5) respectively. Now dot product for both vectors would be 3/5. angle generated would be arccos(3/5)=53 degrees for BOTH vectors. Which is true, but on opposite sides! so if I use this method, i will still end up with both causing clock-wise rotation. See my dilema? – codemonkey Aug 10 '10 at 11:27
3 possible solutions. 1) Don't use the normal but the direction of the side and subtract 90 degrees as mentioned above. 2) Simulate the same by swapping x and y of the normal and inverting one (multiply by -1). 3) Multiply the angle with the sign of the cross product of the two vectors as the crossproduct represents the sin of the angle which is not symetrical around 0 degrees. – Kaj Aug 10 '10 at 13:23
The dot product doesn't give you the angle, only the magnitude of the angle, you also need direction of the angle. All 3 ways above simulate using the sine giving you the side. You could also use basic trig to get the angle. Sin(alpha) = length opposing side / length sloped side (based on a triangle with one 90 degree angle between opposing side and sloped side). That and pythagoras to calculate the sides lengths will do. – Kaj Aug 10 '10 at 15:01
By the way, reread my original answer, as it does solve the dilemma by taking the angle with the plane instead of the normal and subtracting 90 degrees. – Kaj Aug 10 '10 at 15:39

First get the surface tangent from the surface normal: t = (ny, -nx)

Then you can get the velocity component along the surface as vt = v dot t.

Now you can calculate the rotation of the ball: w = |(normal * r) cross vt|, where r is the radius of the ball.

Here I assume the ball has no rotational inertia and begins to spin instantly at the speed it would if it was to roll along the surface. You can use a coefficient of friction to make it more realistic and, if you want, take into account the rotational inertia of the ball.

share|improve this answer
Thanks for the answer Danik. I am already taking into consideration the ball's rotational inertia (by adding it to the new rotation) and also the friction of the surface as a coefficient to be multiplied by the total rotation speed. The more the friction, the higher the speed of rotation, right? – codemonkey Sep 5 '10 at 15:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.