0 votes

So I got bullet (RigidBody2D) and an object (RigidBody2D), and I want to make the bullet pierces through an object and detect it with "onbodyentered" signal without colliding with the object (because it will change the direction and the angle of the bullet on collides).

Any help will be appreciated. Thank you!

in Engine by (15 points)

2 Answers

+1 vote
Best answer

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.

by (18,443 points)
selected by

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 onareaentered on the Area2D object with circle collision ball size like. Do you know why?

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.

0 votes

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

https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html#physics-process-callback

by (19 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories