Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Blade_Dragnal · Apr 19, 2019 at 03:33 AM · projectilepongprediction

3D Projectile Prediction Plane

I want to make a 3D pong style game. I thought of making a prediction plane to tell the player where the ball may go. This was going to be a vertical plane because the ball would not be affected by gravity because pong's ball was never affected by gravity. I have no idea how this would be done because I am new to game design. I would appreciate the help.

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 metalted · Apr 19, 2019 at 01:12 PM 0
Share

I think this is more math than game design. You will need to calculate the path the ball will take in order to find the point its going to end up. As with the old pong, I believe the bounce angle is decided by how far the ball lands from the center of the paddle. So in your case, because it will be a plane paddle ins$$anonymous$$d of a line paddle, every point on the plane will relate to a certain bounce angle.


When you know the bounce angle and the position of the paddle, you can figure out the position it is going to end up. $$anonymous$$aybe it will bounce of the wall so you will need to do some extra calculation for that. At the end, what you want, is a function where you can enter the position of the paddle and the location of the paddle hit, which will output a position on the other side of the playing field. I wouldn't worry about the wall bouncing just yet. I think that if you can get this working, flipping a direction when hitting a wall will be easy-peasy.


This would be the way I would try to accomplish this. So I hope it will help you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by highpockets · Apr 19, 2019 at 02:51 PM

You can raycast out and draw a line renderer to show your predicted path and you could show as multiple bounces, but you would likely want to cap the amount of predicted bounces to 4 for example or it could get quite messy. You can also have an effect to notify players if the prediction is such that the ball bounces out of bounds if the paddle isn’t in the right spot. When you know the direction that the ball is travelling, let’s say it always moves along its positive x axis for example:

 Vector3 ballDir = ball.transform.right;
 

Just do raycasts against colliders and return the reflected direction vector and keep doing that for the amount of reflections / predicted bounces that you want to show and save each reflection point in an array that you pass to the line renderer:

 public LineRenderer predictionLine;
 Vector3 [] reflectionPoint;
 
 void Start(){
 
 predictionLine.positionCount = 5;
 reflectionPoint = new Vector3[predictionLine.positionCount];
 
 }
 
 void Update(){
 
 reflectionPoint[0] = ball.transform.position;
 Vector3 ballDir = ball.transform.right;
 Vector3 predictionDir = ballDir;
 RaycastHit hit;
 
 for(i = 1; i < reflectionPoint.Length; i++){
 
 if (Physics.Raycast(reflectionPoint[i - 1], predictionDir, out hit, Mathf.Infinity)){
 
 reflectionPoint[i] = hit.point;
 predictionDir = Vector3.Reflect( predictionDir, hit.normal);
 }
 else
 {
 //if raycast doesn’t hit a Collider make the remaining line renderer point positions offscreen in-line with the last prediction direction
 reflectionPoint[i] = reflectionPoint[i - 1] + ( predictionDir * 1000 ); //you can also do something to notify that the ball is predicted to go out of bounds here
 }
 
 }
 
 predictionLine.SetPositions(reflectionPoint); //show prediction via line renderer
 
 }


Hopefully that helps and you get the idea. Code not tested

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

106 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 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

Trajectory Prediction with Particle Systems 1 Answer

Can't think of a way to get slow moving projectiles to sync across a network. 1 Answer

2D projectile trajectory prediction 2 Answers

Tank AI, 2d rigidbody projectile trajectory prediction 0 Answers

how to draw trajectory of rocket for faux gravity in unity???? 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