- Home /
Football Curl Shoot Logic and Approach on different swipe gesture?
Hello Folks,
I want to make football kick game. I was able to achieve the linear shoots logic on swipe at any angle but I was not able to crack a way to curl the ball with respect the swipe gesture.
I'm looking for something like wind factor on ball when i hit it according to my swipe. For example, I swipe from center to the deep left side then ball should curl like a curve toward left from center.
Please suggest be the curl shoot approach according to swipe gesture.
Thanks in advance.
Here is the code where I've achieved flick logic:
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
couldswipe = true;
startTime = Time.time;
startPosition = Input.mousePosition;
} else if (Input.GetMouseButton (0)) {
Vector3 touch = Input.mousePosition;
Vector3 touchDelta = touch - startPosition;
if (touchDelta != Vector3.zero) {
if (Mathf.Abs (touch.y - startPosition.y) < comfortZone) {
couldswipe = false;
} else {
couldswipe = true;
}
} else {
if (Mathf.Abs (touch.y - startPosition.y) < comfortZone) {
couldswipe = false;
}
}
} else if (Input.GetMouseButtonUp (0)) {
if (couldswipe) {
endPosition = Input.mousePosition;
float deltaTime = Time.time - startTime;
Vector3 finalPos = endPosition - startPosition;
float speed = finalPos.magnitude / deltaTime;
float swipeDistX = (new Vector3 (Input.mousePosition.x, 0, 0) - new Vector3 (startPosition.x, 0, 0)).magnitude;
float swipeDistY = (new Vector3 (0, Input.mousePosition.y, 0) - new Vector3 (0, startPosition.y, 0)).magnitude;
if (swipeDistY > minSwipeDistY) {
float swipeValueY = Mathf.Sign (Input.mousePosition.y - startPosition.y);
if (swipeValueY > 0) {
float swipeValueX = Mathf.Sign (Input.mousePosition.x - startPosition.x);
if (swipeValueX > 0) {
// Debug.Log ("Right Curl Swipe");
/* Right Curl Logic here */
Vector3 RightCurlForce = new Vector3 (finalPos.x, KickPower, finalPos.y).normalized * speed * forceFactor;
Debug.Log ("Force: " + RightCurlForce);
rigidbody.isKinematic = false;
rigidbody.AddForce (RightCurlForce);
StartCoroutine (ReturnBall ());
} else if (swipeValueX < 0) {
// Debug.Log ("Left Curl Swipe");
/* Left Curl Logic here */
Vector3 LeftCurlForce = new Vector3 (finalPos.x, KickPower, finalPos.y).normalized * speed * forceFactor;
Debug.Log ("Force: " + LeftCurlForce);
rigidbody.isKinematic = false;
rigidbody.AddForce (LeftCurlForce);
StartCoroutine (ReturnBall ());
}
} else if (swipeValueY < 0)
Debug.Log ("Swiped Down (Swipe Upward side to shoot the ball) " + swipeValueY);
}
}
}
}
yes, it swipe away the ball in whatever position in world where you lift your touch up.
I'm concern about curl. how to curl the football on your different swipe gestures.
Answer by Graham-Dunnett · Jun 13, 2014 at 11:59 AM
Don't you just track the position of the finger as it makes a swipe? If the swipe is curved, then curl the ball. I guess typically the first half of the swipe is linear and defines a direction, and then use the distance of the end of the swipe from this line to determine how much curl to add.
That's the same I was planning to do, but output was not upto mark.
If I have irregular swipe curve, my object tends to move in same irregular curve path, as I have stored all my swipe points in a vector list and added the relative force on every delta positions at certain distance.
$$anonymous$$y object should move in a curve not in according to the swipe path I make.
well i was able to flick the ball only by touching the ball but all i want to limit the force and at constant height and it shud make curve @Narendra did u implemented this one..
Answer by Adishah11 · Sep 20, 2018 at 05:41 AM
Check this asset its has both 2d and 3d implementation link: https://assetstore.unity.com/packages/tools/physics/2d-and-3d-swipe-ball-control-96912?aid=1100l3bpb
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Swipe Wind 2 Answers
Finding the starting and ending coordinates of a flick / swipe on iOS 2 Answers
Pick 2D object with touch in Unity 4.3 0 Answers