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
2
Question by oliver-jones · Nov 26, 2013 at 09:13 AM · physicsballanglesaimmaths

Ball Aiming System

Hello,

I'm trying to make a ball aiming system so when a user hits a ball, they can see where the ball is going to go. Like what you see on many snooker games.

Right now, I have a raycast that fires forward into the aim direction which draws a Line Render when a ball is in the ray. But this isnt accurate, as for one, it doesn't take the ball radius into account.

I also want to so the deflection of the balls, very much like this:

alt text

So I need to take into account the balls entire radius, so maybe some kind of capsule raycaster, from there, I then need to calculate the deflection of the ball that was initially aimed and fired, and the direction of the ball that was hit by the initial. I have a little something:

 if (Physics.Raycast (t1, direc, h1, Mathf.Infinity, l2)){
 
     Debug.DrawLine (t1, h1.point, Color.red);
     radiusDummy.localPosition.x = 0;
 
     Debug.DrawLine (radiusDummy.position, h1.transform.position, Color.blue);
 
     //var reflection = direc + 
     //Debug.DrawLine (radiusDummy.position, h1.transform.position, Color.green);
 }

So the t1/h1 raycast is firing from the very most edge of the ball on the left side, and fired forward (where the user is aiming). RadiusDummy is basically a duplicate of the collider radius of the initial ball, but I have to move this manually at the moment. When I move this dummy on the Z axis until its barely touching another ball, the Blue DrawLine is positioned from the centre of the dummy, to the centre of the ball it is touching - this calculates the directional hit of this ball.

First of all, is using this dummy method good? How can I move it automatically? Secondly, I now need to calculate the deflection of the initial ball.

Would appreciate the feedback I can get. Thanks.

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 Oscar-Bear · May 25, 2017 at 03:42 PM 0
Share

Hi! I found your question by searching on google. Do you already have figured out how to take into account the radius of the ball? I'm curious because i have the same problem. All the best! -Oscar

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by smallbit · Nov 26, 2013 at 12:35 PM

I have read once a tutorial how to make that aiming and deflection trick on pool game. The general Idea was to cast invisible ball in the direction of your shooting until it collides with something. Haven't thought on the Unity application but you could cast some invisible or alpha 0 sphere with trigger or something like that. I will just write here the theory they used for that (sadly I couldn't find the article)

Than there was so math geometry involved: If there was collision detected between balls G and 2, the where to go ball vector was starting from the ball that was hitting (in you case letter G) in the direction of ball that was hit (2) from center to center. Than you multiply it to have it a little bit longer

The deflection was based on angle between direction of shot and the above mentioned where to go vector in perfect world if would deflect at 90 degrees I think. Note that in your image the vector of deflecting going back from G does not appear to be correct, that vector is parallel to the whereTogo vector.

Than of course there were issues about the polycount for ball that the higher it was the smoother and more precisely looking the ball collisions were.

Here you have some theory on elastic colisions (including balls) and some formulas for force etc (http://en.wikipedia.org/wiki/Elastic_collision)

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

Answer by umair_hassan · May 19, 2015 at 10:48 AM

Use trail renderer for simple ray making....

http://docs.unity3d.com/Manual/class-TrailRenderer.html

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

19 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

Related Questions

Simulating the graphics of a rolling 3D ball in a 2D game 2 Answers

Player-controlled rigidbody ball sometimes slowing down for no reason 0 Answers

How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers

Ball jump on collision problem 1 Answer

Simple Collision Deflection (Pong) 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