Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ondesic |
In my “Main.tscn” scene there is RigidBody2D named “Ship”. It is an instance of Ship.tscn. The Ship visually starts at position (20,20) and has the following children Nodes:
RigidBody2D (named "Ship")
CollisionShape2D
Sprite
in the Main.gd code I initialize the Ship’s position with the following code:
$Ship.position = Vector2(300,300)
However, even though the Ship object visually moves to (300,300), the collision occurs at position (20,20) and not at (300,300).
Any ideas as to what is happening?
A few things:
-
In the editor, toggle on the “Visible Collision Shapes” debug
option. In v2.x it is in located at the top of the editor to the
right of the play and stop buttons. In v3.x it is located under the
Debug menu option in the top left. This will show the collision
shapes while you run in the editor. You may want to hide your ship
Sprite to make it easier to see. -
What code are you using to determine the collision position?
-
Are there any other physics objects near the ship’s start position
at the start of the game?
2D||!2D | 2018-03-17 12:48
Correct me if I’m wrong, but the CollisionShape and Sprite are children of the RigidBody. Therefore if I move the RigidBody, shouldn’t the children move with it?
I don’t have separate code to move the CollisionShape because it is a child of the RigidBody
ondesic | 2018-03-17 19:20