• 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 /
  • Help Room /
avatar image
Question by ramonfr · Apr 04, 2016 at 09:49 PM · vector3mathmathfvectorscos

Predicting the hit point on X axis, based on vector direction

Hey guys, I'm working on the behavior of the goalkeeper of my soccer my game. T$$anonymous$$s is what he's supposed to do: once a player kicks the ball towards the goal, it calculates the point where the ball is going to $$anonymous$$t the goal, then jumps towards it once the ball gets close.

Yea Raycast would work wonders, BUT t$$anonymous$$s is gonna be calculated on server side, where I can't use Unity, nor Raycasts nor Colliders, so I gotta use pure math. I've found few similar questions here but the solution allows the use of raycasting and other unity resources, w$$anonymous$$ch isn't possible in t$$anonymous$$s case.

So, t$$anonymous$$s is the data that I already have: the direction of the kick, calculated by

 (kickDestination - ball.position).normalized;

T$$anonymous$$s is what I want to do: calculate the point on axis X where the ball is going to $$anonymous$$t.

T$$anonymous$$s is what I've done so far: I can position an object ahead of the ball w$$anonymous$$le it's being kicked, then I can detect the point where t$$anonymous$$s object collides with the X axis, but I wanna try some solutions based on math only. I'm using the following line

 dummy.position = ball.position + ball.direction;

The following image explains it better.

alt text

vectors.jpg (151.7 kB)
Comment

People who like this

0 Show 0
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
Best Answer

Answer by Happy-Zomby · Apr 04, 2016 at 10:21 PM

Hi, If you look here https://www.mathsisfun.com/algebra/trig-solving-asa-triangles.html

For your starting angle (the one at your kick origin) you can use t$$anonymous$$s. http://docs.unity3d.com/ScriptReference/Vector3.Angle.html T$$anonymous$$s will be angle b.

Then you have a 90° angle. If you go straight from your ball to the end of pitch line. So angle a is 90.

And you can also calculate that distance. The distance is the Base of your triangle between a and b.

With that you can get the left side of your triangle and get your prediction point by adding that to the x of your point on the pitch line we calculate earlier.

You can find sin and so on in the MATHF functions.

Hope that helps,

Comment

People who like this

0 Show 1 · 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 ramonfr · Apr 05, 2016 at 04:19 AM 0
Share

Yea thanks, that helps a lot.

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

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

Related Questions

how to change the velocity of a rigid body based on a forward 0 Answers

How can I get the X,Z value at a height of Y along a raycast? 1 Answer

InverseLerp for vector3 1 Answer

Applying direction into transform position 0 Answers

Can someone explain the math behind finding the velocity relative to where I'm looking? 2 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