• 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
1
Question by MikezNesh · Jun 20, 2010 at 01:11 PM · iphonevelocityflick

Flick Determines Velocity...

I am trying to set up a 3D ragdoll flicking game as test app. In this app I need to know how to set up a script where your flick determines your velocity (like in a flick basketball game).

I did some research and found this: http://answers.unity3d.com/questions/7258/iphone-flick-shooting

But time determination is lame. Does anybody know how to set up a professional script? That would be much appreciated.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Peter G · Jun 20, 2010 at 01:35 PM

Try something like this that updates in real time. It takes the first tap and measures the change in position since the last frame.

//js function Update () {

  var i : int = iPhoneInput.touchCount; 

  if(i > 0) {//check to make sure we have at least 1 touch

     var touch : iPhoneTouch = iPhoneInput.GetTouch(0); //Get the first touch

     var delta : float = touch.deltaPosition.magnitude; //the magnitude of 
     //the change in that touch's position.  Read this value for your

     delta /= Time.deltaTime; //the input is in pixels per second;
     //or take this line out and you have pixels per frame, but frames are
     // less consistent, but over a second, you will gather the actual pixels 
     //per second.
  }

}

P.S. I didn't check this code so there may be a typo or two.

Comment
Add comment · Show 11 · 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 MikezNesh · Jun 20, 2010 at 02:09 PM 0
Share

How do I get the angle and add the force? For the force do I multiply a constant variable and the magnitude? How would I multiply the magnitude?

avatar image Peter G · Jun 20, 2010 at 04:11 PM 0
Share

You can technically add force however you want. I would either use rigidbody.AddForce and multiply one of the components by delta. In that case, I would remove the last line of the code and add force every frame that the finger is down. Or you could use rigidbody.velocity = Vector3.up delta someSpeed. In which case you might collect delta for several frames and find the average velocity. I don't quite understand what the angle script is doing on the other page, so I don't know what angle you need, screen or world space?

avatar image MikezNesh · Jun 21, 2010 at 01:03 AM 0
Share

How would I do the one you recommended (the rigidbody.AddForce)? Also, what is the difference between world space and screen (i'm kind of new to unity) ?

avatar image Peter G · Jun 21, 2010 at 11:51 AM 0
Share

To use rigidbody.AddForce, you pass a Vector3 so it might look something like rigidbody.AddForce(Vector3.up * delta). That would add force to the object going straight up in world space. If you want local space then you have to transform.TransformDirection(Vector3.up);. That leads into your next question. Unity has 4 different view spaces. Screen space is organized so that everything is based on the position it appears on the screen. The bottom left corner is (0, 0) and the top right corner is (screen.width, screen.height). The other space that is dependent on the screen is the...

avatar image Peter G · Jun 21, 2010 at 11:57 AM 0
Share

normalized viewport. This is like the screen space because everything is relative to the position on the screen, but it is normalized so the bottom left corner is (0, 0) and the top right is (1, 1). Local space is relative to the objects parent. If the object doesn't have a parent, then local space is world space. That leads to world space. World space is centered around the origin so an object that is 10 units forward would be at (0,0,10). Typically, when you move a character, it is in world space. His different parts are all being animated in local space, but the entire character is..

Show more comments
avatar image
0

Answer by MD-Unlimited · Dec 20, 2011 at 11:26 PM

Hi im new to scripting and i like the sound of this and would help me a great deal but I have applied this to a gameobject and the camera but the script does't seem to do anything for me. All I want to be able to do is roll a ball to a character and this seems to be really hard to find out how to do.

Many thanks.

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

iPhone Flick shooting 1 Answer

ExecutionEngineException: Unity 3 on the iPhone 2 Answers

iphone unity lights don't render in the phone 0 Answers

Play streaming video. Unity for Iphone 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