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 Andsomesan · Jul 19, 2013 at 01:19 PM · trajectorypredictionsimulate

Trajectory prediction basketball

I need some help to get it right. I did some research and managed to get something done, but it isn't work how it should. I use a second ball to give the basketball force , angle ... aldonaletto script. I have some line renderer working but not how it is supposed to be. So if anyoane can help me that will be great. I have another plane who let me move the invisible ball up and down not only left and right. The prediction won't work in some positions(I get this error:rigidbody.velocity assign attempt for 'ball(Clone)' is not valid. Input velocity is { NaN, NaN, NaN }. UnityEngine.Rigidbody:set_velocity(Vector3) Force:Update() (at Assets/Scripts/Force.cs:98) ) and my ball don't follow the path everytime. If i want to hit the floor and then bounce to the hoop , first it make some sort of an arc then go to the ground and nothing else.

     void Update()
     {
         if(Input.GetKey(KeyCode.Escape))
         {
             Application.LoadLevel(1);
         }
         
         var referenceForward = Vector3.up;
          var referenceRight= Vector3.Cross(Vector3.up, referenceForward);
         var newDirection = ball2.transform.position - playerFire.transform.position;
         var angle = Vector3.Angle(newDirection, referenceForward);
         unghi = angle;
         
 //        Distances = Vector3.Distance(Input.mousePosition, new Vector3(ball2.transform.position.x, ball2.transform.position.y, 0));
         
         if(Input.GetButton ("Fire1"))
         {
             //path simulation
 //            simulatePath();
             mousePoz = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
             
             if(mousePoz != Vector2.zero)
             {
                 ray = Camera.mainCamera.ScreenPointToRay(mousePoz);
                 
                 if(Physics.Raycast(ray, out hit, Mathf.Infinity))
                 {
                     ball2.transform.position = new Vector3(hit.point.x, hit.point.y, 0);
                 }
             }
         }
         
         if(Input.GetButtonUp("Fire1"))
         {
             rigidbody.useGravity = true;
             rigidbody.velocity = BallisticVel(myTarget, shootAngle);
         }
     }
     
     Vector3 BallisticVel(Transform target, float angle)
     {
         Vector3 direction = transform.position - target.position; // get target direction
         float     height = direction.y; // get height difference
         direction.y = 0; //retain only the horizontal direction;
         float    distance = direction.magnitude; // get horizontal distance;
         float     a = unghi *  Mathf.Deg2Rad; //convert angle to radians;
         direction.y = distance * Mathf.Tan(a); //set direction to the elevation angle;
         distance += height / Mathf.Tan(a); //correct for small height difference
         // calculate the velocity magnitude
         float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2 * a));
         return velocity * direction.normalized;
     }

Here it is my update function and Ballistic. Now the simulation path function :

 //    void simulatePath()
 //    {
 //        Vector3[] segments = new Vector3[segmentCount];
 //        segments[0] = playerFire.transform.position;
 //        Vector3 segVelocity;
 //        
 //        Vector3 direction = transform.position - ball2.transform.position; // get target direction
 //        float     height = direction.y; // get height difference
 //        direction.y = 0; //retain only the horizontal direction;
 //        float    distance = direction.magnitude; // get horizontal distance;
 //        float     a = unghi * Mathf.Deg2Rad; //convert angle to radians;
 //        direction.y = distance * Mathf.Tan(a); //set direction to the elevation angle;
 //        distance += height / Mathf.Tan(a); //correct for small height difference
 //        // calculate the velocity magnitude
 //        float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2 * a));
 //        segVelocity = velocity * direction.normalized;
 //        
 //        for(int i = 1;i < segmentCount; i++)
 //        {
 //            
 //            if(segments[i] != ball2.transform.position)
 //            {
 //                float segTime = (segVelocity.sqrMagnitude != 0) ? segmentScale / segVelocity.magnitude : 0;
 //                segVelocity = segVelocity + Physics.gravity * segTime;
 //                RaycastHit hit;
 //                
 //                if(Physics.Raycast(segments[i-1], segVelocity, out hit, segmentScale))
 //                {
 //                    segments[i] = segments[i-1] + segVelocity.normalized * hit.distance;
 //                    segVelocity = segVelocity - Physics.gravity * (segmentScale - hit.distance) / segVelocity.magnitude;
 //                    segVelocity = Vector3.Reflect(segVelocity, hit.normal);
 //                }
 //                else
 //                {
 //                    segments[i] = segments[i-1] + segVelocity * segTime;
 //                }
 //            }
 //            
 //        }
 //        Color startColor = playerFire.nextColor;
 //        Color endColor = startColor;
 //        startColor.a = 1;
 //        endColor.a = 0;
 //        sightline.SetColors(startColor, endColor);
 //        
 //        sightline.SetVertexCount(segmentCount);
 //        for(int i=0; i < segmentCount; i++)
 //            sightline.SetPosition(i, segments[i]);
 //    }

i use only x and y but the ball after it been launched can bounce anyware

Thanks in advance and sorry for my bad english.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Andsomesan · Jul 19, 2013 at 02:32 PM

after some minor modification to segment scale and how many they are i made my ball follow the path. So that let me with those problems: how can i fix that error and how can i make my ball bounce from the ground to the hoof. I think that i will need much more force, but that sort of arc still be in my way to get it done.

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

How to create a 2D parabolic trajectory prediction line with javascript? 1 Answer

Trajectory prediction 0 Answers

2D Trajectory/Path Predictor 0 Answers

Trying to make a trajectory prediction line! 1 Answer

Calculate Velocity of Impulse 0 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