• 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 thornekey · Mar 31, 2014 at 02:03 PM · physicsball

Fling a ball?

How would fling a ball or object with the mouse. So lets say i have a set of goals, and i want the player to click and drag (in a fling motion) and when they click the ball is spawned, and then where they their mouse moving towards initially is where the ball start heading..

heres an example:

alt text the box is the goal. circle is the ball. the red line represents the ball direction and where its heading the green line is the mouse direction and where its heading. the start of the green line is where the player clicked and where the ball was spawned.

1.png (7.5 kB)
Comment
Add comment · Show 4
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 ava4414 · Mar 31, 2014 at 03:07 PM 0
Share

are you program$$anonymous$$g in C# or js and for pc ios or android?

avatar image koray1396 · Mar 31, 2014 at 03:56 PM 0
Share

if the fling will be realtime with the ball, you can just simply create a vector of mouse movement of a short time limit(0,5s?), and apply force to the ball in the direction and magnitude. Otherwise, if you want further mouse movement to be effective, then it will be more complicated and you would need to apply weighting.

avatar image thornekey · Apr 01, 2014 at 10:51 AM 0
Share

@ava4414 : C# and pc

@koray1396 : could u give an example, that sounds complex! aha

avatar image flamy · Apr 07, 2014 at 07:25 AM 0
Share

i wonder who downvotes! dont see like anything is wrong with the question!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jamesflowerdew · Apr 01, 2014 at 11:03 AM

This uses mouse or finger to generate an force called pPush, which is then applied to a ball.

nFrame is Time.deltaTime all other vars with a "p" in front need declared at the top of your script.

 void FingerThing(float nFrame){
             pGo=false;
             if(Input.GetKey(KeyCode.Mouse0)){
                 Vector2 vFinger = Input.mousePosition;
                 Vector3 vPlace = this.camera.ScreenToWorldPoint (new Vector3 (vFinger.x,vFinger.y,100));
                 
                 
                 if(!pOldPress){
                     pTime=nFrame;
                     pStartPos=vPlace;
                 }else{
                     pTime+=nFrame;
                 }
                 pFirePos=vPlace;
                 pOldPress=true;
             }else{
                 if(pOldPress){
                     pPush=(pFirePos-pStartPos)/pTime;
                     pGo=true;
                 }
                 pOldPress=false;
             }
         }
         
Comment
Add comment · Show 4 · 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 thornekey · Apr 01, 2014 at 11:11 AM 0
Share

ohh i see.. where would the spawning go though?

avatar image thornekey · Apr 01, 2014 at 03:56 PM 0
Share

That doesnt really help

avatar image jamesflowerdew · Apr 01, 2014 at 11:03 PM 0
Share
  void Update(){
         float vFrame=Time.deltaTime;
 FingerThing(vFrame);
         if(pGo){
         pGo=false;
         GameObject ball=(GameObject)Instantiate($$anonymous$$yBallPrefab,wherever,Quaternion.identity);
         WhateverScriptITHas vScript=ball.GetComponent<WhateverScripItHas>();
         vScript.YouShould$$anonymous$$oveWithThisVector(pPush);
         }
         }
 
avatar image thornekey · Apr 07, 2014 at 07:15 AM 0
Share

didnt work..

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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 avatar image avatar image avatar image

Related Questions

Get a free moving ball. 1 Answer

I am having a problem trying to simulate football(soccer) physics 2 Answers

How could I make a bouncy object move mostly along the Z axis? 1 Answer

Need help with the physics and angles of gerbils in a plastic ball.. 2 Answers

How to predict where the ball will fall? 4 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