Fast rigidbody goes through walls

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gokudomatic2
:warning: Old Version Published before Godot 3 was released.

I think this question was asked not long ago already, but I can’t find it anymore.

My project is a classic 3d FPS game. One weapon I’m implementing is a grenade launcher. I use a RigidBody for the grenade.

Problem: the grenade must be projected with a reasonably fast velocity (e.g Vector3(0,0,20)). However when its linear velocity is above 10, it goes through walls (typical staticbody). This will probably be fixed in godot 3. But in the meantime, how can I fix that?

I remember something about changing the project preferences to increase the collision precision of the physics engine, but I can’t neither find the solution in QA (maybe it was for 2d only) nor find the option in the project’s preferences.

Note: by the way, I didn’t implement any custom integrator. I use the standard behavior of the rigidbody.

:bust_in_silhouette: Reply From: kubecz3k

Try to check Continuous Collision detection (“Continous Cd”) inside RigidBody.

I already tried this option, but it makes no difference.
Sorry to not have mentioned before.

Gokudomatic2 | 2016-04-09 10:41

Ok in this case I don’t have any good ideas, you can probably increase fixed_fps parameter in project settings but I don’t think it’s really a good idea… In this case you probably will need to make collision shape of walls wider… or predict collision probability manually and decrease velocity in that case (you could do this for example with a lot bigger area (or raycast that is faced towards granade velocity) that could report that wall is near… but this probably would be easier to do if we could have proper collision mask/layers in 3d)

kubecz3k | 2016-04-09 10:56

:bust_in_silhouette: Reply From: dc1a0

Problems of this type are generally that the fast moving object skips over the collision area. Ways to fix this are:

Make your walls thicker than the distance the moving object will travel in a single frame

Use a raycast to detect when the moving object is close

Use an invisible area to expand the collision checking area.

Thank you for your suggestions. It might be however difficult to implement them.
About thickness of the walls, I’m afraid I don’t have such thing. I have meshes that represent rooms, and walls are the faces of the room. Their thickness is therefore unlimited. It is not like gtkradiant, which have thickness for every wall.

About raycast, I prefer to avoid extra complexity in the node because it’s a bullet and there can be lot of them and it must be performant. And I’m not sure how to implement that since I don’t know where to point the raycast. Rigidbodies rotate in every direction.

And what do you mean for an invisible area? That’s what I use for standard bullets because they must be destroyed when they hit a wall. But a grenade must bounce against the wall.

Gokudomatic2 | 2016-04-09 18:21

For raycast, you could have them point from the grenade, in the direction it’s heading, for the invisible area, you could either have it on the grenade to expand it’s collision area and act like a raycast, or you could attach it to the wall and expand the wall’s collision area.

in all cases, if the closest object or wall, (depending how you decided to set it up) is closer than the grenade will move next frame. you can tell it to only move that distance to make it look like it hit the wall (and then explode or bounce or whatever else you want.)

dc1a0 | 2016-04-09 18:39

I’m not sure to understand what you mean. I’m not implementing anything in my grenade. There are no custom integrator, no script. The physics engine does all the work.

Gokudomatic2 | 2016-04-09 18:47

It’s been my experience that the physics engine won’t be able to do all of it. for example, the physics engine can’t reliably tell it when to explode. Ranging from the issue you’re having, to not telling the grenade to explode 60 times. In the end, it will likely need to have some code. So may need code to decide what happens when it gets close, but not close enough as well.

In the meantime, you could also add the code to an invisible area for the walls, that tell objects that are close to them how to behave.

dc1a0 | 2016-04-09 18:56

Sure I manage in a script somewhere when the grenade must explode. But about the movement of the body, I want to use the standard behavior of the physics engine. After all it’s his job.

Gokudomatic2 | 2016-04-09 19:00

It’s the physics engine’s job to handle objects, not YOUR objects, there’s a difference. From my experience, It’s generalized so that it can be customized to do the specific things someone wants it to do. That’s why GDscript has bindings to access physics engine functions. Out of the box it’s designed to handle most general tasks capably, not everything specifically. That’s where you step in to provide the specifics.

dc1a0 | 2016-04-09 19:58

Alright. Thanks for the explanation.
It’s still hard for me to believe I have to manage myself a round object simply falling on the ground, rolling on a slop and bouncing against a wall, only because it’s going too fast at the beginning. But if it’s a limitation of the physics engine, there’s no way around.

Gokudomatic2 | 2016-04-09 20:12

Think about it, from my understanding so far, your wall is only something like 1 pixel thick. if the grenade is moving farther per fame than the size of the grenade, when is the grenade supposed to record the collision, given that according to the computer they never overlap?

dc1a0 | 2016-04-09 20:16

Indeed. That’s pretty much the cause of the problem. I was looking for a way to change the number of calculated frames per second to have a better precision.

Gokudomatic2 | 2016-04-09 20:27

well, changing the calculated frames, per second wouldn’t do much good given that your grenade would still be moving too far per frame as it is now. You possibly could raise the physics fps, but then you’d have to raise the idle fps as well so it didn’t go out of sync when you slowed down the grenade. There’s also another setting that can increase or decrease the calculations, but I’m not certain I understand that one very well to know if it’d be useful in your situation. Much less give any guidance on it.

That’s why I suggested increasing either the detection area for the grenade or the wall to compensate for close in a manner you could control it in a way you could make it look perfect to players who wouldn’t need to know better.

dc1a0 | 2016-04-09 20:35

:bust_in_silhouette: Reply From: Toupoc3

I’m sure it is probably far too late to respond to this but had a similar problem and I discovered the cause of the issue in my project. I’m thinking my solution may still be of some use to you. My answer, unfortunately, comes in the form of a question; What mode is the bullet’s rigid body in? Is it “Character” mode? Kinematic mode? Anything but Rigid mode? If so, switch it to “Rigid Mode” and make the collision shape convex. It seemed to work for me.