2016-10-12 18:24:46

Hi guys,
So I was wondering, how can I calculate the damage a ball does to a block based on its movement angle based on the speed? You don't have to provide code, but I was wondering what the math formula was. I've looked this up a few times, but can't find exactly what I'm looking for.

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2016-10-12 21:35:55 (edited by magurp244 2016-10-12 21:37:22)

Hmm, I think you'd have to apply trigonometry to calculate the angle, then add/subtract from velocity to simulate deflection. So, taking the direction and velocity i'd calculate a line to find a point of collision, then use the line to calculate the Adjacent and Opposite angles, depending on whether the ball is moving vertically or horrizontally. Then, depending on the degree of the angle i'd add/subtract the velocity to increase or decrease the damage output.

The Longest Side is the the Hypotenuse, the equation to find it is:

Tangent: tan(0) = Opposite divided by Adjacent

The Adjacent angle is parrallel to the Hypotenuse, the equation for finding it is:

Sine: sin(0) = Opposite divided by Hypotenuse

The Opposite angle moves in the opposite direction to the adjacent angle, its equaitions is:

Cosine: cos(0) = Adjacent divided by Hypotenuse
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2016-10-12 22:43:13

Well, okay. so I have this idea.
I can calculate the ball's theta.
I can then calculate the angle distance between the ball's theta, and the spot its edge smacked the brick.
I can then multiply the cosine of this distance angle by the total movement speed of the ball.
I can then do the deflection steps, although this topic was about damage so I'll not go into detail about that here.
Maybe?

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2016-10-13 07:09:31

Bleh, I think this is considered more 2D Physics actually, I haven't played with this stuff all that much so appologies if its not that helpful. You could actually do it on collision instead of calculating a line, I dug up a Pong example in python [link] that likely has collision/deflection code you could use, although i'm not sure what language your using.

The general idea is that velocity is the measure of power with the angle being the percentage of that power being transfered to the surface, or damage in other words. So if you drop a ball straight down at a 90 degree vertical angle relative to a flat surface that would impart 100% of its power/velocity to that surface, if you throw the ball at a 45 degree angle towards the ground it would be 50% power, 22.5 degree angle 25% power, etc. So you'd calculate the balls angle relative to the surface and convert it into a percentage, for example:

32 degree angle / 100 = 0.32 * 90 total degrees = 28.8 percent

Then you use that to calculate the percentage of velocity power to damage the surface:

(28.8 angle/100) * 84 velocity = 24.192 power

This gives you the remaining power, or damage, that would be applied to the surface, in this case 24.192 damage with a total velocity of 84 at a 32 degree angle of impact.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2016-10-13 22:45:58

wow, thank you. So if I have that right, it's
90 degrees is a direct straight collision.
Calculate the actual angle the ball is colliding with the block though, we'll say it's 32 like you did.
Divide by 100
Multiply by 90 since that's the maximum angle of collision.
Divide by 100
Multiply by the total velocity.
Subtract that last calculation from the block's strength.

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2016-10-14 01:06:06

Oops, I think I borked my math. I think its divide 32 angle by 90 total degree's, then multiply velocity by the result to get power. So:

32 angle / 90 total degree's = 0.355556 percent * 84 velocity = 29.966667 power
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2016-10-14 12:52:24 (edited by CAE_Jones 2016-10-14 12:53:58)

Hmm.
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.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2016-10-14 22:28:48

Basically what I'm trying to do is:
ball.speed is the speed vector so
ball.speed.x is horizontal speed, ball.speed.y is back and forward speed.
ball.speed1 is ball's total speed, all the vector values absolute values added together, velocity in other words.
ball.theta was the calculated angle distance between 0, 0, with a theta of 0, and the ball's speed x and y entered as coordinates. Therefore, if the ball's x speed was 10 and its y speed was 10, its theta would be 45 degrees because 10, 10, is 45 degrees away from 0, 0, with a theta of 0. I can post the angle distance calculation function if you want me to.
ball.v is the ball's coordinates vector.
ball.v.x, ball.v.y is the position of the center of the ball.
ball.radius is the radius of the ball.
ball.weight is the weight of the ball.
block is the block object
block has x, y, strength.
If the ball collides with a block, I use Magurp244's calculation to calculate how hard it hit based on ball.theta and ball.speed1, then multiply that result by ball.weight. weight is a hole number.
Then to deflect it, I would have:
If the ball collided with the block to its left, I would first add the collision angle to the theta, and then invert the theta, to spin it to the right.
If the collision was to the right, I would think I would subtract the collision angle and then invert.
  I'm not calling anyone wrong, and I'm not saying this is the right and only right way and I refuse to change it based on anything you guys say. I was just clearing up how I was doing things because I don't feel like I did before.

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support