Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Following on from my previous question: I have the ball quite realistically bouncing from surfaces it hits. Now I'd like to make it spin from the friction of the hit.

Showing this is simple enough: I rotate the ball by its angular velocity every tick and apply the same rotation when it's rendered.

When a ball hits a wall, I know that the speed of rotation is affected by...

  • the ball's initial speed when hitting the surface
  • the friction coefficients of the ball and surface (physical constants)
  • the angle of incidence (the angle between the ball's incoming velocity vector and the surface normal).

The angle of incidence is approximated by the dot product of the ball's impact and exit velocity vectors. (1 meaning high spin, -1 meaning no spin, and everything else relatively in between)

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 expected. Except for one thing: It would always rotate clock-wise (because of positive values).


Is this a good method? Can you think of a simpler way?

If this method seems fine, what am I missing? How do I know when the ball should be rotating counter-clockwise?

share|improve this question
add comment

4 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
add comment

Ó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
add comment

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
add comment

The first thing you need to adress is wheter the rotation speed or spin before hitting the wall; lets say Si; is greater, equal or lower than the value needed to maintain the same spin after hitting, say Ss. With this you can get the actual after hitting spin, say Se, using a friction value between the ball and the surface

Get the velocity component across the bouncing surface Vxi= Vi dot Vx, being Vx a parallel vector to the surface with magnitude 1.

The value you are looking is Ss= Vxi/r , this is to transform Vxi into angular speed. If Si is lower than Ss the ball should gain spin positively. If Si is equal to Ss the ball should keep aproximately the same spin, about this later. If Si is greater than Ss the ball should lose spin

the loses and gain of speed depend on the frictional value Fr. Actually it is a Cross between the radius and hte frictional force, but you can set that value as you wish.

You must also notice that besides the bounce coef, the ball loses some energy due to a friction between the ball and surface, thus Vxi is affected negatively. I would say bounce coef affects Vy and friction affects Vx.

You should take into account the deformation of the ball. This will affect the time or frames the ball is stick to the wall, thus the fritional force will exert for a longer time affecting spin and exit velocity. This deformation depende on how you want your model to be.

share|improve this answer
add comment

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.