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