-1
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The simplest possible solution would be to maintain the horizontal velocity, and flip the sign of the vertical velocity, after multiplying it by an elasticity factor.

vec2 velocity;
vec2 position;

position += velocity * dt;
if (collision)
{
   position = adjust_position(); // to not collide anymore
   velocity.y = -velocity.y * elasticity;
}

If you're only concerned with a 2D projectile, on a flat plane, this should work.

The elasticity factor will control how far the projectile will bounce. If you make it 1, it will bounce as high as the initial path. Typical values are lower than 1, which means the projectile will lose energy with each bounce.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.