# Flick Determines Velocity...

 0 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. more ▼ asked Jun 20 '10 at 01:11 PM MikezNesh 843 ● 64 ● 74 ● 93 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Jun 20 '10 at 01:35 PM Peter G 15.1k ● 16 ● 44 ● 137 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? Jun 20 '10 at 02:09 PM MikezNesh 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? Jun 20 '10 at 04:11 PM Peter G 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) ? Jun 21 '10 at 01:03 AM MikezNesh 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... Jun 21 '10 at 11:51 AM Peter G 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.. Jun 21 '10 at 11:57 AM Peter G add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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. more ▼ answered Dec 20 '11 at 11:26 PM MD-Unlimited 1 ● 1 ● 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
Be the first one to answer this question

By Email:

Topics:

x3892
x2014
x330
x10

asked: Jun 20 '10 at 01:11 PM

Seen: 3499 times

Last Updated: Dec 20 '11 at 11:26 PM