# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Posted: Sun Apr 16, 2017 11:30 pm

Joined: Tue Jan 31, 2017 8:07 pm
Posts: 39
I'm attempting to simulate a "ricochet" effect for the bullets I fire from my gun, but can't seem to get them to behave as intended. Basically, the bullets are rigid bodies with a box shape and the following values:
Code:
float bulletPower = 100.0f;
glm::vec3 bulletVelocity = cameraDirection * bulletPower;

bulletRigidBody->setLinearVelocity(btVector3(bulletVelocity.x, bulletVelocity.y, bulletVelocity.z));
bulletRigidBody->setRestitution(0.4);

// And the floor/walls have restitution of 0.9

However, the bullets fly into the scene, bounce quite a bit the first time, then when they hit another surface they stop almost dead in their tracks.

How can I achieve a ricochet effect, where the bullets bounce off of surfaces multiple times and slowly lose their velocity, rather than after about one bounce?

Cheers.

Top

 Posted: Mon Apr 17, 2017 12:46 pm

Joined: Mon Apr 17, 2017 12:11 pm
Posts: 2
The combined restitution is .4 x .9 = .36, so within the second bounce, not accounting for linear damping, the energy is down to 13% (and by E=0.5mv^2 that is less than 2% of the original velocity) so you need to up the coefficient of restitution.
Have you tried enabling continuous collision detection? The proper calculation of the restitution might depend on the accuracy of the impact velocity, which if calculated conservatively to avoid instability would reduce the bounce effect even more.
From my own experience basing the bounce velocity on the previous frame's velocity makes the simulation much more stable for restitution (especially for resting stacks) with discrete collision detection.

Top

 Posted: Mon Apr 17, 2017 4:44 pm

Joined: Tue Jan 31, 2017 8:07 pm
Posts: 39
I have continuous collision detection enabled for the bullet body, yes (I should have mentioned that). It's only needed for the moving body and not the static objects it collides with, correct?

As for the restitution, I found information online that stated that anything above 1.0f would result in the body actually never losing momentum (continuing to bounce higher and higher), is that not accurate?

Quote:
From my own experience basing the bounce velocity on the previous frame's velocity makes the simulation much more stable for restitution

How do you do this exactly? This sounds like a good solution.

Top

 Posted: Tue Apr 18, 2017 7:00 pm

Joined: Mon Apr 17, 2017 12:11 pm
Posts: 2
jimjamjack wrote:
Quote:
From my own experience basing the bounce velocity on the previous frame's velocity makes the simulation much more stable for restitution

How do you do this exactly? This sounds like a good solution.

Apologies, forgot to emphasize that this is in my own physics engine and not in Bullet. It was done as a trade off to to avoid the bouncing bodies gaining energy from actually impacting early between two steps when using discrete collision detection. It also trades away propagation so Newton's cradle fails.

For Bullet, I think you must increase the restitution, because as I said it is the product of the restitution scalars of the involved bodies that is used for the bounce (when I checked the source code on GitHub). Just keep all scalars below 1.0. Other than that you could also control the bullet's speed manually and count the number of bounces before letting it die off by itself. This is just general advice as I have next to no knowledge of Bullet.

Top

 Posted: Tue Apr 18, 2017 10:11 pm

Joined: Tue Jan 31, 2017 8:07 pm
Posts: 39
No worries! It looks like playing around with the restitution and velocity until I hit the sweet spot is the way to go about it, unless there's a clever way of playing around with velocity each frame...

Either way, thanks for the suggestions.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot] and 18 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities