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 siddharth3322 · Jul 14, 2014 at 06:02 AM · collisionprojectilebouncetrajectory

Trajectory Projectile with Collision Detection

Right now I am trying to create projectile for cannon in which I want to detect collision also.

At present I have simple working projectile after using two references

Unity – How to display projectile trajectory path in Unity 3D?

Path/Trajectory prediction – What path will the object take

But in this I also want to represent bounce in projectile path. I searched everywhere but didn't find any useful content.

Please provide some guidance here.

Comment
Add comment · Show 6
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 CodeMasterMike · Jul 14, 2014 at 06:15 AM 0
Share

You will need to read up on some physics to get that right. I don't know how to do it properly, but I would do probably do something like this:

When the cannon ball lands on the ground, calculate another trajectory path, based on the angle of the ball had when landing and its speed. And take into account how "bouncy" the ground is, since the less "bouncy" the ground is, the less will the canon ball bounce.

avatar image siddharth3322 · Jul 14, 2014 at 06:34 AM 0
Share

But before throwing ball, I want to display projectile motion with ground collision detection.

avatar image CodeMasterMike · Jul 14, 2014 at 06:40 AM 0
Share

Then you still need to calculate the whole trajectory including the bounces first, and then draw them like that unity link you posted.

You need to make a collision check for every step to know when to calculate a bounce. And how to do that, all depends on how you have setup your game environment.

avatar image siddharth3322 · Jul 14, 2014 at 06:47 AM 0
Share

Then how to detect collision, At present in game environment I have only four walls not anything else. But for projectile I can't able to detect collision. Thanks for your suggestions.

avatar image CodeMasterMike · Jul 14, 2014 at 07:06 AM 0
Share

Unity have collision objects which you can use. Use a simple BoxCollider on all objects. Get the Bounds from the objects, and see if they intersect on every update. If they intersect there is a collision.

This is a VERY simple way, and will not work very well if you use objects that doesnt fit into a BoxCollider, so you really need to read up on collisions to get it right.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tehnique · Jul 14, 2014 at 06:18 AM

I'd start from here.

First, set drag and angular drag to 0 on the projectile (rigidbody), set all friction settings to 0, and bounciness to 1, on the projectile material.

Second, use your normal trajectory prediction/drawing algorithm (I suppose you have one from the links you posted), up until the first collision. When you have a collision, predict the bounce using a SphereCast to get the RaycastHit where the ball would hit the collision object. From the RaycastHit, get the Normal component and use Reflect with the raycast direction as inDirection and the RaycastHit.Normal as inNormal. This will give you the resulting vector of the bounce. Continue from there with your normal bouncing algorithm to find trajectory after bounce.

Later Edit: In order to use the SphereCast for your scenario do the following:

Select the last 2 points of the path (pointA-before last and pointB-last).

  • Make sure the first point (pointA) is above ground. If not, reselect your points as the ones before them (so A is last-2, B is last-1). Go to -> and repeat until the first point is above ground.

When you have PointA above ground calculate the vector from pointA to pointB. This is your SphereCast direction, and pointA (above ground) is your SphereCast origin. Run your SphereCast and continue as described above.

With all friction settings set to 0, your ball should behave as the SphereCast.

Comment
Add comment · Show 15 · 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 siddharth3322 · Jul 14, 2014 at 06:28 AM 0
Share

I have already gone through Vector3.Reflect. I want to draw path of moving object before it fires from cannon with bounce and collision detection.

avatar image Tehnique · Jul 14, 2014 at 06:48 AM 0
Share

To do it realistically, I would simulate the path first with an identical object that I do not render to the player. If nothing changes afterwards, the second path should be identical.

avatar image siddharth3322 · Jul 14, 2014 at 07:01 AM 0
Share

At present I am working on clone of this type of game http://www.2dplay.com/flick-headers-euro-2012/flick-headers-euro-2012-play.htm

In that I don't have time to throw dummy object and calculate position for it as per my assumption.

avatar image Tehnique · Jul 14, 2014 at 07:22 AM 0
Share

Try to set all the friction/material settings as in my original answer, and use SphereCast, RaycastHit.Normal and Reflect to predit the trajectory. With the mentioned friction/material settings, the ball should behave almost exactly like the SphereCast predicts (whn bounce is involved). You'd have to run the SphereCast very close to the object on which you bounce, so you can approximate the ball hit trajectory as straight (before bounce).

avatar image siddharth3322 · Jul 14, 2014 at 07:27 AM 0
Share

@Tehnique, Thanks for all these suggestions but all these confusing me at present so please update your answer and provide story in clear way.

Show more comments

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

23 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

Related Questions

Ball Isn't following Trajectory line : Unity3d 1 Answer

A node in a childnode? 1 Answer

Bounce when hitting wall 2 Answers

Unity Messing up Basic Math? Projectile Trajectory Algorythm 1 Answer

Increase velocity without changing trajectory 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