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 LeakySink · Dec 14, 2012 at 09:38 PM · raycastvelocityforcetrajectorypreview

Predicting the path of a ball from it's forward vect

Hi all,

There are plenty of questions that seem similar to mine but I've not been able to factor them into a solution for my situation.

I have a camera with an invisible object parented to it, I then fire a ball from that position in it's forward direction using addforce.

What I need is a way to predict the trajectory of the ball and display a target object (just a cube at the moment) at that location, it needs to account for hitting obstacles in the way.

I've tried several solutions, the one that's been most successful is to create an invisible object every frame adding the same force in the forward direction and reporting the position at which it hits (then destroying it). This provides the effect I'm after but it's very laggy and unresponsive as it can take a while for the invisible projectiles to actually hit a surface.

Any help would be greatly appreciated.

Thank you.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Loius · Dec 14, 2012 at 10:15 PM

You might need to cheat it. It's possible to predict trajectory accurately, but hopefully you don't need perfection.

You have just a ball, right? You can use your level data (Colliders), multiple Spherecasts and Vector3.Reflect to approximate the ball's trajectory. Cast out a certain distance; if there's a collision, back up by an appropriate amount, reflect your direction around the vector from hit.point to the sphere's center assuming that point is on its surface (there's probably a function to get that vector), and continue casting until you run out of desired projection distance.

Comment
Add comment · Show 2 · 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 LeakySink · Dec 14, 2012 at 10:31 PM 0
Share

Hmm I'm not sure how this helps me, I need to know where the ball will hit the wall or floor, as in most games with a grenade arc for example.

avatar image Loius · Dec 15, 2012 at 03:11 AM 0
Share

Well I've never implemented it, or I'd give better particulars. If you need to simulate gravity as well just give your casts a bit of a downward slope - you'll have to to it iteratively in this case, to simulate gravity creating a 'slope' as the ball moves.

something like:

 point : ball.position;
 direction : ball.velocity;
 simgravity : 0.0;

 while( dist > 0 ) {
   simgravity -= 9.81;
   direction = (direction + simgravity).normalized;
   Cast(from point to point + direction, max distance = 1.0)
   if hit {
     scale down gravity based on hit point relative to ball     center
     reflect direction around hit point -> ball center
   }
   dist -= 1;
 }

You can make it immensely simpler by not worrying about reflection, and just calculate the arc until the first collision (Off the top of my head, I know $$anonymous$$GS4 does this). It's the same idea, just add gravity iteratively.

avatar image
0

Answer by sparkzbarca · Dec 14, 2012 at 09:53 PM

itween

(google it, its a downloadable asset)

trajectory prediction instantly is actually alot of math.

Comment
Add comment · Show 2 · 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 gabs · Dec 14, 2012 at 10:04 PM 0
Share

tweening != trajectory prediction. With tweening, you already know the end value before starting.

avatar image LeakySink · Dec 14, 2012 at 10:33 PM 0
Share

Are you suggesting animating the ball to a point using itween rather than adding a force?

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

12 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

Related Questions

Gravity trouble: Falling slow, jumping fast 1 Answer

Convert Force into Velocity for 2D Player Jump 0 Answers

remove forward component from velocity vector 2 Answers

Setting limits to my trajectory 2 Answers

What is this variable type? 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