Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Narendra · Jun 12, 2014 at 06:35 AM · swipefootballflickkick

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);
 
                                 }
                         }
                 }
         }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hgaur725 · Jun 12, 2014 at 08:49 AM 0
Share

Hey did u implemented the swipe on the Ball

avatar image Narendra · Jun 13, 2014 at 10:46 AM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hgaur725 · Jun 13, 2014 at 12:10 PM 0
Share

can u elaborate it more in much more simple way plz

avatar image Narendra · Jun 16, 2014 at 04:30 AM 0
Share

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.

avatar image hgaur725 · Jun 16, 2014 at 04:56 AM 0
Share

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

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Make a bowling ball spin on a swipe path 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges