Hi, I'm programming a Football/Soccer game, currently I'm working on the height of the kick. The game is top down so I'm simulating the height of the ball with calculations and visual aids.
The kick consists of a 2d vector with it's magnitude (force) and it's direction. From this information and the angle of the kick in the z-axis (height,
angle a in the image) that I assign according to the force, I want to get the z-component of the vector.
From hours of researching I get that I can get the x-component like this: std::abs(magnitude) * cos(angleInDegrees) and the y-component like this: std::abs(magnitude) * sin(angleInDegrees). But of course I have these components in the vector itself.
I have this so far for the z-component:
initialAngle = getAngleRelativeToForce(force); // this returns an angle from 0 to 60 according to the force of the kick (this works fine)
b2Vec2 resultingVector = force * direction;
float sinAngleY = resultingVector.x / std::abs(force); // angle between y-axis and hypotenus (x-component/hypotenuse)
// Formula for z-component: Force * sinAngleY * sin(initialAngle)
forceInZAxis = std::abs(force) * sinAngleY * std::sin(Game::DegreesToRadians(initialAngle));
This gives me weird behaviors: for example similar kick with huge height when I'm facing up, and no height when facing down. Or a strong kick with no height.
I'm stuck there, I keep reseraching but I feel there is something I'm missing and maybe someone can point it out.