- Home /
how to shot a soccer ball in curve path according to the swipe type
How to move the soccer ball in curve path?? Please some one help me... I have to write a logic for swipe type.... If I will swipe vertically than the ball should travel straight to the goal. If I will swipe in curve shape for example, in "C" shape then it should travel in "C" path. If swipe in opposite "C" shape than it should travel in opposite "C" path. Please someone help me
This is the link for the game. I think this game is only available for iPhone or Android,
http://pikpok.com/games/football/
Please help me in writing the logic
@tenthplanet0 plz do rply man.. m also doing kind of same thng
plz can u tell me how to make soccer ball curve when flicked by user.. plz help me out
Answer by robertbu · Jan 18, 2013 at 08:39 PM
If you are using the Physics engine, you will need to add a small force at every frame to simulate the Magnus effect to make the ball curve. If you are simulating physics, then you can use something like a sine curve or a exponential curve to model the movement.
For detecting the "C" you would need capture all the points of movement in the stroke and evaluate them... something like find the max distance of any point from the line connecting the start and end points. The distance from the line could determine the amount of curve, the length of the line could set the initial velocity of the ball, and the which side of the line the max point is found would indicate which way the ball would curve.
Thanks robertbu....I will check it out and if come across any problem then will definitely revert to you. Please be in contact to help me further... Thanks again
I played a bit with getting a soccer ball to curve just to see how it looked. Here is a bit of test code:
using UnityEngine;
using System.Collections;
public class Soccer : $$anonymous$$onoBehaviour {
Rigidbody rb;
bool b$$anonymous$$icked = false;
void Start () {
rb = GetComponent<Rigidbody>();
transform.eulerAngles = new Vector3(0.0f, 15.0f, 0.0f);
}
void Update () {
if (b$$anonymous$$icked) // Curve force added each frame
rb.AddRelativeForce (Vector3.left*0.05f, Force$$anonymous$$ode.Impulse);
}
void On$$anonymous$$ouseUp(){
rb.AddRelativeForce (Vector3.forward*2.0f+Vector3.up*1.0f, Force$$anonymous$$ode.Impulse);
b$$anonymous$$icked = true;
}
}
Attach to a sphere with a Rigid body, set the size and mass values to something close to a soccer ball, and click on the sphere.
As for detecting the distance from a point to a line for the swipe, see this post:
http://answers.unity3d.com/questions/62644/distance-between-a-ray-and-a-point.html
@robertbu applied this script its working Perfect But problem is the ball is making curve even if i flick the ball straight.. i want it to curve when user try to make curve gesture.. and plus the curve is making in one direction i.e to left..
@hgaur725 - This answer demonstrates how to make something curve. It is not a complete solution with a curve gesture. Unity Answers is here to help you write your own code. I believe there are other, perhaps more complete answers to a curving ball. They don't include a curve gesture. There are still other answers that explore how to capture a curve gesture. It is up to you research them and then at least make an attempt to put your script together. If you get stuck, post a new question along with detailed specifics on what you are trying to do along with your code attempt. If you get stuck with part of the problem, post back with a single, specific technical question.
@robertbu...Sir All i want when user Flick the ball.. and he try to make curve using his fingers then the ball should get curve.. i used the script u provided.. but the problem with that script is that when i flick the ball straight it takes the curve automatically .. plz sir help me out...
Answer by Piflik · Jan 10, 2013 at 11:42 AM
Use rigidbodies and its methods (AddForce etc) and all of that will be handled by the physics engine.
Answer by benhumphreys · Mar 06, 2014 at 10:21 AM
Instead of trying to do something complex like gesture-recognition, instead record the position of the touch/mouse at each frame, and work out the distance and direction between it and the previous frame.
So each frame you will get a small change.
Use these to add forces to the ball and make it curve in the same direction.
@benhumphreys can plz explain this via sum refernce script or smthng like that..in which a ball is flicked on touch.. and if we make gesture of curve it goes in curve.. thanx in advance..
@robertbu...Sir All i want when user Flick the ball.. and he try to make curve using his fingers then the ball should get curve.. i used the script u provided.. but the problem with that script is that when i flick the ball straight it takes the curve automatically .. plz sir help me out...
Answer by Adishah11 · Sep 20, 2018 at 05:42 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
How To Get The Position And Rotation For ALL The Children Of An Object For An Animation At Once 0 Answers
Evaluating Animation Curves in Full 0 Answers
How to move objects along a curve? 0 Answers
how to shot a soccer ball in curve path according to the swipe type 2 Answers
Animation rotation property with right angle curve 0 Answers