• 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 Kunddizzle · Apr 07, 2010 at 10:51 AM · iphoneflick

iPhone Flick shooting

Hey

Im working with unity and iPhone, and I need to use a "flick" to shoot.

A "slow" (a flick = 1sec) should result in a slow shooting speed, and a "fast" flick (flick = 0.1 sec ?) should result in a fast shot.

What are the standards for a flick? 150pixel at the y-axis? cant seem to find any information.

for (var i = 0; i < iPhoneInput.touchCount; i++) {

     var touch = iPhoneInput.GetTouch(i); 

     if (touch.phase == iPhoneTouchPhase.Began) {
         cachedTime = Time.time;
         firstFinger = touch.position;

     } else if (touch.phase == iPhoneTouchPhase.Moved) {
         if (touch.position.y-firstFinger.y &gt; 150 ) {

             throwTime = (Time.time-cachedTime);
                         // Max (slowest) throwTime
             if (throwTime &gt; 0.75) {
                 throwTime = 0.75;   
             }

             Shoot(throwTime);
             break;  
         }
     } else if (touch.phase == iPhoneTouchPhase.Ended) {
         cachedTime = 0;                     
     }           

}

I also tried with deltaPosition.y, but then I couldnt use a "slow" shot...

It seems to work OK (above), but im not satisfied. Could need some tips!

Thx

Comment
Add comment · Show 1
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 poonam shendge · May 30, 2014 at 06:34 AM 0
Share

what is inside "Dart.Update();" could you pls elaborate more?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by e-bonneville · Apr 07, 2010 at 12:24 PM

Here, try this script:

var mouseStart; var mouseEnd; private var GetVelocity = false; var DartVelocity; var FlickTime = 0; var flickLength = 0; var DartSpeed = 0; var worldAngle; var thrower = false; var rotate = false;

function Update () { if (Input.GetButtonDown ("Fire1")) { GetVelocity = true;
mouseStart = Input.mousePosition; }

     if (Input.GetButtonUp ("Fire1")) {
     GetVelocity = false;
     mouseEnd = Input.mousePosition;

     GetSpeed(); 
     GetAngle();

     Debug.Log ("The speed of your throw was " + DartSpeed);
     Debug.Log ("The angle of your throw was " + worldAngle);
     thrower = true;
     rotate = true;
     Dart.Update();
     }

     if (GetVelocity) {
         FlickTime++;
         }       

}

function GetSpeed () { flickLength = (Screen.height - mouseStart.y) - (Screen.height - mouseEnd.y); if (FlickTime > 0) { DartVelocity = flickLength / FlickTime; } DartSpeed = DartVelocity / 10; DartSpeed = DartSpeed - (DartSpeed * 2); }

function GetAngle () { worldAngle = camera.ScreenToWorldPoint (Vector3 (mouseEnd.x, mouseEnd.y, (camera.nearClipPlane - 100))); }

That's what you're trying to do. It uses Fire1 for the input, but you can change that to whatever you want. You can have a slow speed and a fast speed. It also calculates the angle for you and outputs it as worldAngle. DartSpeed is the speed of your projectile (I was using a dart). Hope this helps!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

A node in a childnode? 1 Answer

Flick Determines Velocity... 0 Answers

How do I pause and unpause my game on the iPhone? 1 Answer

Unity games and web comunication 1 Answer

Can't select audio clip even though it's there 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