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 hgaur725 · Mar 12, 2014 at 09:21 AM · touchtouchscreengestures

how to flick ball in the finger direction

using TouchScript.Events; using TouchScript.Gestures; using UnityEngine;

public class FlickExample_Rotator : MonoBehaviour {

 public Rigidbody Target;

 private Quaternion targetRotation;
 private Vector3 speed;
 public bool test;

 private void Start()
 {
     GetComponent<FlickGesture>().StateChanged += flickHandler;
     GetComponent<PressGesture>().StateChanged += pressHandler;
      Target.transform.eulerAngles = new Vector3(0.0f, 0f, 0.0f);
     Target.AddTorque(0,0,0);
 }

 private void pressHandler(object sender, GestureStateChangeEventArgs gestureStateChangeEventArgs)
 {

// Target.angularVelocity = Vector3.forward;

 }

     void Update()
 {

     //SendMessage("Follow",SendMessageOptions.DontRequireReceiver);
     Target = GameObject.FindGameObjectWithTag("Football").rigidbody;

 }
 private void FixedUpdate()
 {

     if (speed != Vector3.zero)
     {
         Target.AddForce(speed);
         Target.AddTorque(5,5,5);
         speed = Vector2.zero;
     }
 }

 public void flickHandler(object sender, GestureStateChangeEventArgs e)
 {
     //if(test== true)
     {
     if (e.State == Gesture.GestureState.Recognized)
     {
         var spd = ((sender as FlickGesture).ScreenFlickVector/(sender as FlickGesture).ScreenFlickTime);
         speed = new Vector3(Mathf.Clamp(spd.x,-500,500),Mathf.Clamp(spd.y,-450,450),-((camera.nearClipPlane - 1000)));


         SendMessage("DontFollow",SendMessageOptions.DontRequireReceiver);
         spd = speed;
     }
     }
 }

 void OnGUI()
 {
     if(GUI.Button(new Rect(0,0,100,50),"Reload"))
     {
         Application.LoadLevel(Application.loadedLevel);
     }
 }

}

[1]: /storage/temp/23461-flick.txt

I am using this script which is flicking the ball. but it is not flicking the ball properly in the direction of finger..

flick.txt (1.7 kB)
Comment
Add comment · Show 6
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 · Mar 12, 2014 at 09:33 AM 0
Share

Help me plz.

avatar image haim96 · Mar 12, 2014 at 09:37 AM 0
Share

please edit your question and paste the code into it. then select the code and press the "code sample" button (with 01010 icon...)

avatar image ShadoX · Mar 12, 2014 at 09:38 AM 0
Share

Perhaps

 speed = new Vector3($$anonymous$$athf.Clamp(spd.x,-500,500),$$anonymous$$athf.Clamp(spd.y,-450,450),-((camera.nearClipPlane - 1000)));

doesn't calculate the direction correctly?

avatar image hgaur725 · Mar 12, 2014 at 09:44 AM 0
Share

@shadox: i am having this script which is also flicking ball.`#pragma strict var factor = 100.0;

private var startTime : float; private var startPos : Vector3; var cam : GameObject; var target : Rigidbody;

function Awake() { gameObject.GetComponent(testing).enabled = true; } function Update() { cam = GameObject.FindGameObjectWithTag("$$anonymous$$ainCamera"); target = GameObject.FindGameObjectWithTag("Football").rigidbody;

} function On$$anonymous$$ouseDown() { startTime = Time.time; startPos = Input.mousePosition; startPos.z = transform.position.z - Camera.main.transform.position.z; startPos = Camera.main.ScreenToWorldPoint(startPos);

}

function On$$anonymous$$ouseUp() { var endPos = Input.mousePosition; endPos.z = transform.position.z - Camera.main.transform.position.z; var temp : Vector3 = transform.position; temp.y = $$anonymous$$athf.Clamp(0,temp.y *.5f,0); transform.position = temp; endPos = Camera.main.ScreenToWorldPoint(endPos); cam.Send$$anonymous$$essage("DontFollow",Send$$anonymous$$essageOptions.DontRequireReceiver);

  var force = (endPos - startPos);
 force.z = force.magnitude;
 force /= (Time.time - startTime);
 target.AddRelativeForce(Vector3.forward *2, Force$$anonymous$$ode.Impulse);
 rigidbody.AddForce(force * factor);

// ReturnBall(); }

function ReturnBall() { yield WaitForSeconds(4.0); transform.position = Vector3.zero; rigidbody.velocity = Vector3.zero; }

function OnGUI() { if(GUI.Button(Rect(0,0,100,50),"Reload")) { Application.LoadLevel(Application.loadedLevel); } }`

avatar image hgaur725 · Mar 12, 2014 at 09:46 AM 0
Share

can any one tell me clear way as i am new to unity

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

How do I move an object with my finger?[C#] 1 Answer

How to trigger sound only when both fingers lifted off screen 1 Answer

A touch'es state is always Began and the position doesn't change 1 Answer

Transitioning from different number of touches causes behavior overlap 0 Answers

Please help. Attempting touch controls but I cant figure out what I'm doing wrong 3 Answers


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