Are we talking damage based on momentum?
Or are we trying to get how much of that is used based on the angle?
Or are we deflecting things?
Ball Vs line:
line_angle=atan2(line.y2-line.y1, line.x2-line.x1) ball_vel_angle=atan2(ball.v.y, ball.v.x) ball_vel_magnitude=sqrt(ball.v.y*ball.v.y + ball.v.x*ball.v.x) ball_momentum=ball.mass*ball_vel_magnitude force1=ball_momentum/dt # where dt is the amount of time which passes between the start of the collision and the calculation. # (decrease ball_vel_magnitude here, based on how much the ball's speed should decrease with the collision. I don't think I've ever gotten a straight answer for that other than it depending on the properties of the objects, so pick the appropriate restitutions and go from there.
#I think you want to reflect the ball over the line's perpendicular perpendicular=atan2(-(line.x1-line.x1), line.y2-line.y1) # I'm iffy about this. I know a perpendicular line has the negative recipracle of the slope, and slope and tangent are more or less equivalent, so I think this should work. new_angle=perpendicular+(perpendicular-ball_vell_angle) ball.v.x=ball_vel_magnitude*cos(new_angle) ball.v.y=ball_vel_magnitude*(new_angle)
I think that does something like what you want? Use force1 to calculate damage (if it's not in the ranges you want, throw in a constant multiplier to represent mass or hardness or something).
If you want the damage to be how much of the force is perpendicular to the line, multiply force1 by cos(perpendicular-ball_vel_angle), iiuc.
_______________________________________________ Audiogames-reflector mailing list Audiogamesemail@example.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector