Quote:
Why is contact point based on VSpeed arrow and not angled vector arrow?
ContactPoint is always point on line between point P0 and P1 closest to ball.
If ball is in contact with flipper and ContactPoint is in range <0.0, ..., 1.0>, it is point of contact.
If ContactPoint is outside this range, ball can touch only one of cylinders. If ContactPoint < 0.0 then it is "bigger cylinder" if > 1.0 it is "tip" of flipper.
Ball.Velocity (speed vector) will only point at correct "contactpoint" if that vector is perpedicular to line P0 - P1. In other conditions is uselses.
Also, _prehit() will be executed just before ball hit flipper. In that last moment "Hit" property will be set to TRUE and ContactPoint will point exactly place where ball is touching flipper.
Quote:
Is there a way to know the angle of the vector?
Yes. It is visible at image. You need only calc arcus tanges of BallHSpeed, BallVSpeed.
Before i put here needed function, you should know, that it is not reliable.
If in one frame ball move vector is pointing at flipper (BallVSpeed > 0), ball in that frame will hit flipper and flipper is in move, when in next frame:
- ball may be still in contact with flipper (but not alway will be, ball may be faster than flipper)
- ball move vector will point "UP" (BallVSpeed < 0.0), away from flipper
In that case that ball move vector is more/less "reflection" vector from previous frame + effect of flipper move.
Here is correct arcus tangens function with "example":
Code:
Const RadToDeg = 57.295779513082320876798154814105
' Convert X, Y to angle.
' Need example? See Atn2Example.
Function Atn2(x, y)
If x > 0 Then
Atn2 = Atn(y / x) * RadToDeg
ElseIf x < 0 Then
Atn2 = 180 - RadToDeg * Atn(y / -x)
ElseIf y > 0 Then
Atn2 = 90
Else
Atn2 = -90
End If
Atn2 = Atn2+90
End Function
Sub Atn2Example()
AddDebugText Atn2( 0, -100) ' Up = 0
AddDebugText Atn2( 10, -100)
AddDebugText Atn2( 100, -100) ' Up/Right = 45
AddDebugText Atn2( 100, -10)
AddDebugText Atn2( 100, 0) ' Right = 90
AddDebugText Atn2( 100, 10)
AddDebugText Atn2( 100, 100) ' Down/Right = 135
AddDebugText Atn2( 10, 100)
AddDebugText Atn2( 0, 100) ' Down = 180
AddDebugText Atn2( -10, 100)
AddDebugText Atn2( -100, 100) ' Down/Left = 225
AddDebugText Atn2( -100, 10)
AddDebugText Atn2( -100, 0) ' Left = 270
AddDebugText Atn2( -100, -10)
AddDebugText Atn2( -100, -100) ' Up/Left = 315
AddDebugText Atn2( -10, -100)
End Sub
' Atn2Example ' <-- unrem this line to see Atn2 example
You would use this Atn2 function like this:
Dim ball_to_flipper_angle
ball_to_flipper_angle = - Atn2( LeftFlipperExt.BallHSpeed, LeftFlipperExt.BallVSpeed )
Quote:
It seems to me that the ball vector angle and flipper angle are both useful to account for...
Yes, but i think it will be hard to make any good decision based on ball move angle vector and flipper angle.
I think BallVSpeed and BallHSpeed is better. First both values are just ball move vector in relation to flipper.
In relation to flipper:
- if BallVSpeed > 0.0 then ball is goin "down" to flipper. Also force how much ball will push flipper is proportional to BallVSpeed (not Ball speed, because angle will change that force)
- if BallVSpeed < 0.0 then ball is moving away from flipper
- if BallHSpeed == 0 then ball move vectore is perpedicular to flipper surface
- if BallHSpeed < 0.0 ball is moving to LEFT
- if BallHSpeed > 0.0 ball is moving to RIGHT.
In short, it is not easy to get same information based on flipper angle and ball move vector.
Quote:
In above image it looks like ball won't even contact flipper at all?
Probably will not. Maybe if flipper will be in move "up". My image is just exaple how that vectors and points P0 & P1 looks. If i put it on image with ball touching flipper all would look harderd to understand.
----------------------
Tomorrow i will put samples with "prehit" subroutines.