Screen Wrap collision problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SENIO

Hi !
I try to make an Asteroid classic game, have my ship with ability to shoot a bullet and asteroid with no movement for now.

Have doing this for wrapping :

onready var screen_size = get_viewport_rect().size

func screen_wrap():
position.x = wrapf(position.x, 0, screen_size.x)
position.y = wrapf(position.y, 0, screen_size.y)

My problem is before wrap, my collision work fine (bullet and ship collide perfectly to my asteroid object) but when i wrap, no matter the side, my collision is no more detected and my ship and my bullet just cross my asteroid. Dont know why.

If someone as the answer.

Thank you in advance

(Sorry for my english)

:bust_in_silhouette: Reply From: jgodfrey

Only guessing because you don’t show the relevant code, but I’d guess you’re ship is a Rigidbody2D. You should never manually set the position of a Rigidbody2D (as you’re doing in your screen wrap code) - it’ll break the physics system.

See this answer to a similar question:

https://forum.godotengine.org/74554/does-collision-detection-fail-after-wrapping-around-screen