I was wondering how to figuring out how to slice a ball (banana kick) by flinging it curve-ways. However, according to the LibGDX's gesture listener, the method for flinging only focuses on a straight direction, whether if the ball went to the left, right, or straight.
@Override
public boolean fling(float velocityX, float velocityY, int button)
{
// Set flag for goal.
gotPoint = false;
isBallMissed = true;
// Set flag to enable scrolling goalkeeper when a player's turn as a goalkeeper.
isAIKicked = false;
// Re-adjust ball fling coordinates...
x = velocityX/25;
y = (velocityY/25) * -1;
if(!flingLocked && !gotPoint)
{
if(y > 100) // --> Checks if the gling power is just right or else it miss.
{
if(y > 130)
{
goalpostHit = false;
crossbarHit = false;
disableGoal = true;
meterSpeed = 50f;
} else {
goalpostHit = false;
crossbarHit = true;
disableGoal = true;
meterSpeed = 20f;
}
} else {
goalpostHit = true;
crossbarHit = true;
disableGoal = false;
meterSpeed = 3f;
}
}
// Get the value to set the collision on or off.
bp.setGhostPost(goalpostHit);
bp.setGhostCrossbar(crossbarHit);
// For debugging purposes only. Checks if the fling direction of the ball went. (output display console only)
System.out.println("Hit Post Enabled Status: " + goalpostHit);
System.out.println("Hit Bar Enabled Status: " + crossbarHit);
System.out.println("touchUp() at Y: " + y);
System.out.println("fling() at Y: " + y);
System.out.println("fling() at X: " + x);
// For debugging purposes only. Checks if the fling direction of the ball went.
if(x >= 1)
{
directionStatus = "RIGHT";
} else if(x <= -1) {
directionStatus = "LEFT";
} else {
directionStatus = "FOWARD";
}
if(!goalKeeper && !flingLocked && !freezeGame && !isPaused && !gotPoint) // --> Tells is the ball is flinged or not while the player is under kicker role.
{
// Play SFX.
SFX.getBallKicked().play(1f);
// Set Timer
timer4 = 0;
// Set AI's smart level as a goalkeeper
speedLevel = (rnd.nextInt(175 - 55) + 55);
isReversed = rnd.nextInt(10);
// Set mass of a body.
MassData mass = new MassData();
mass.mass = 400;
// Re-create body of the ball.
wc.getWorld().destroyBody(ballBody);
ballDef.position.rotate(0f);
ballDef.angle = 30f;
ballDef.position.set(rc.getSoccerBallX(), 10);
ballDef.allowSleep = true;
ballBody = wc.getWorld().createBody(ballDef);
ballBody.setActive(true);
ballBody.applyLinearImpulse(x, y, rc.getSoccerBallX(), 10); // --> Makes the direction go left or right?
ballBody.applyAngularImpulse(200);
ballBody.isBullet();
ballBody.setMassData(mass);
ballBody.setLinearDamping(-990f); // --> This will set how fast will accelerate the object will fall. Set it to a negative value to increase falling speed.
ballBody.setGravityScale(0); // --> Set it to negative value and the ball will lift. Set it to a positive value and the ball falls normally.
// Load the ball.
ballLoader.attachFixture(ballBody, "soccer ball", ballFixture, rc.getSoccerBallWidth());
v2.ball_origin = ballLoader.getOrigin("soccer ball", rc.getSoccerBallWidth()).cpy();
// Disable fling and set timer.
switchRoleTimer = true;
flingLocked = true;
// Action ended per turn.
if ((noOfTries < 11) && !isSuddenDeathmatch)
{
noOfTries++;
}
// Disable fling temporarily.
Gdx.input.setInputProcessor(this);
}
return false;
}
What can I do to make the ball fling in curve-ways if I fling it curve-ways? Should I make a flag and mathematically computed the coordinates by analyzing the finger in order to recognize the response of this kind of fling? Take note that I'm making a 2D overview of the soccer game.