Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Matt_UV | |
Old Version | Published before Godot 3 was released. |
Hello,
In my project, I need to add and remove collision exceptions a numerous number of time. The goal is to let the player (RigidBody2D) walk through walls (StaticBody2D).
While the player is inside the wall, I need the collision exception. When it gets out I need to remove it.
The easiest way would be to use Player.add_collision_exception_with(Wall)
at every frame in which the player is in the wall, but I am afraid it would be over-consuming in terms of CPU.
I tried to understand how the method works by looking at the source. I only have basic knowledge in C++, but what I understand is that when you call PhysicsBody2D::add_collision_exception_with()
, it calls Physics2DServerSW::body_add_collision_exception()
, and then Body2SW::add_exception()
When I look at the code in body_2d_sw.h, I can see
[...] VSet``<``RID``>`` exceptions; [...] _FORCE_INLINE_ void add_exception(const RID& p_exception) { exceptions.insert(p_exception);}
Does it mean that the method Player.add_collision_exception_with(Wall)
just adds Wall to a vector of RID without further heavy process ? If I add several times the same collision exception, will it test that the collision exception already exists?
Subquestion: I can’t really figure out what RIDs are, could you explain it please?