Benjamin - thanks for pointing that out. I only ever really visit my own website while logged in, so I see everything. It seems I forgot to give anonymous people permission to download files
THAT could explain why I have no comments on them
lol!
@Julius - thanks. Powershots aren't in yet - but sound like an interesting idea, equally - if powershots go in, then there needs to be an "absorb" shot which slows it back down maybe?
The formula involves vectors... This is my collision function:
function handleCollision(paddle as integer, hit as boolean)
if hit
`Normal of paddle
set vector3 2, cos(object angle z(paddle)), sin(object angle z(paddle)), 0
normalize vector3 2, 2
scale vector3 2, 2, 2.0
`Get unit/normalized version of ball speed
normalize vector3 3, 1
`Temporarily invert
multiply vector3 3, -1
`Get scalar impulse
I# = dot product vector3(2, 3) * 2.0
`Multiply normal vector by it (and store in vector3(4))
copy vector3 4, 2
multiply vector3 4, I#
`Un-invert
multiply vector3 3, -1
`Add to vector 4
add vector3 4, 3, 4
`Normlize
normalize vector3 4, 4
`Scale by speed magnitude
Ball.speed = length vector3(1) * 1.05
if Ball.speed > 30 then Ball.speed = 30
multiply vector3 4, Ball.speed
copy vector3 1, 4
endif
endfunction
Now, basically... It does this:
1) if hit is true - run the function. I must have coded this tired... That's just bloody stupid...
2) Get the normal of the paddle. As I recall (might be wrong) sin/cos produced a parallel vector whereas cos/sin produced a normal. A normal is a vector which is at 90 degree's/perpendicular to its surface.
3) I have the speed of the ball stored in vector 1, I then take the unit or "normalized" version of it and put it in vector 3. The unit vector is basically the same vector in direction, but its length is 1.0 (so its scaled up or down)
4) Invert the speed unit vector - this basically provides momentum in the opposite direction.
5) Dot Product the normal of the paddle and the inverse unit speed of the ball. Dot Product is where it gets a bit voodoo... Suggest you wikipedia/google it or lookup a Vector Tutorial on these forums - I think it was done by Philip... The Dot Product seems to return a float...
6) On a copy of the normal of the paddle, multiply it by the dot product.
7) Inverse out speed unit vector back again
8) Add the speed unit vector to the vector produced by step 6
9) Normalize it (length to 1.0)
10) The ball speed is now the length the original ball speed vector (1) multiplied by 1.05. This causes the ball speed to increase by 5% on each paddle hit.
11) Cap the ball speed at 30 (world units per section...)
12) Set the ball speed vector to the unit vector calculated in step 9 multiplied by the new speed calculated in step 10.
Please dont take this as gospel - I've found a method which seems to "work"
[center]