Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ericdl | |
Old Version | Published before Godot 3 was released. |
I have a small Rigidbody2D icon that shoots Rigidbody2D bullets at a large Rigidbody2D icon. All rigidbodies have scale (1,1). Upon collision, the bullet spawns two sprites: a red burst to show the position of RigidBody2D.body_enter
signal, and a green burst to show the position of state.get_contact_local_pos()
method of the _integrate_forces
function. So far no problem:
The large icon is initially situated at origin (0,0), and the bullets slowly push it across the screen as intended. However, as the large icon moves, the collision bursts unexpectedly move in the same direction away from the collision point:
And things get strange when the large icon is rotated:
The bullets are fired with the apply_impulse
method as follows:
func _fire_bullet():
var bullet = bullet_res.instance()
bullet.set_pos(self.get_global_pos())
bullet.set_z(1)
self.get_parent().add_child(bullet)
bullet.apply_impulse(Vector2(),Vector2(-1,0) * 500)
The red burst is created in the body_enter
signal as follows:
func _body_enter(body):
var red_burst = red_burst_res.instance()
red_burst.set_pos(body.get_global_pos())
self.add_child(red_burst)
body._remove_bullet()
The green burst is created in the _integrate_forces
function as follows:
func _integrate_forces(state):
if (state.get_contact_count() > 0):
var green_burst = green_burst_res.instance()
green_burst.set_pos(state.get_contact_local_pos(0))
self.add_child(green_burst)
Why are the collision positions moving away from the collision point?
Download link to example project: https://drive.google.com/file/d/0BwnfZQAEnciAek1oNW5NbG5rcEE/view?usp=sharing