Topic was automatically imported from the old Question2Answer platform.
So I got bullet (RigidBody2D) and an object (RigidBody2D), and I want to make the bullet pierces through an object and detect it with “on_body_entered” signal without colliding with the object (because it will change the direction and the angle of the bullet on collides).
You’ve just described exactly what an Area2D does.
If you don’t want collisions, bouncing, etc. why are you using a RigidBody2D for your bullet at all? Areas are very often the best choice for bullets for just the behavior you’re describing.
Yeah, I just realized it after I press submit to this question hahaha. Its because I have mindset “if I want to create a moving object, I have to use RigidBody2D type”. Anyway, I’ve tried with Area2D and its working now. But I have one question, somehow if I set the velocity of my bullet too high, sometimes it wont run the on_area_entered on the Area2D object with circle collision ball size like. Do you know why?
apaajabolehd | 2020-09-11 16:45
This is called “tunneling” and has to do with how collision detection works. Bodies are moved by “teleporting” a certain discrete distance each step. If the velocity is high relative to the size of the obstacle, then the movement between frames will skip right over them.
For this reason, a lot of games will use raycasts for high-speed projectiles, rather than actual moving bullets.
so from what i understand you want the bullet to pass through the object and change its trajectory?
my solution: put the bullet on a different collision_mask and use an Area2D to change the bullet trajectory
collision_mask: This describes what layers the body will scan for
collisions. If an object isn’t in one of the mask layers, the body
will ignore it. By default, all bodies scan layer 1.
the bullet wont collide with the object, so you put an Area2D inside the object and have it on the same collision_mask as the bullet
Area2D: Area nodes provide detection and influence. They can detect
when objects overlap and emit signals when bodies enter or exit. Areas
can also be used to override physics properties, such as gravity or
damping, in a defined area.
There are three main uses for Area2D:
Overriding physics parameters (such as gravity) in a given region.
Detecting when other bodies enter or exit a region or what bodies are
currently in a region. Checking other areas for overlap.
Now all you need to do is pass the signal from the Area2D to the bullet and you can modify the bullet trajectory with a script
well, that’s a little bit off from my question though. But, thank you for your answer, it could help me / gimme an idea on future development. I really appreciate it.