godot: Camera2D causing RigidBody2D to not move when rotating

Godot version

4.0.3.stable

System information

Windows 11, gl_compatibility

Issue description

When I disable the camera of my car (self._camera.enabled = false), it moves OK. When I enable it:

self._camera.enabled = self.is_main_player
# self._camera.enabled = false

both in the _ready and _process methods, the car does not move. I also ran print(self.position.x) to observe the position logs and I can see its value changes in a very unusual way — it basically doesn’t move.

NOTE: to reproduce the car movement working and disabling the camera, you must comment exactly like this:

# DO THIS

# self._camera.enabled = this.is_main_player
self._camera.enabled = false

# DON'T DO this

self._camera.enabled = this.is_main_player
self._camera.enabled = false

in both _ready and _process, otherwise the movement won’t work. Looks redundant, but yes.

Steps to reproduce

  • Add a Camera2D to a RigidBody2D
  • Set cam.enabled = true
  • Use the directionals to move the RigidBody2D

Minimal reproduction project

git clone https://github.com/hydroper/carknockonline or https://github.com/hydroper/carknockonline

Pay attention to the comment above when disabling the camera:

# this

# self._camera.enabled = self.is_main_player
self._camera.enabled = false

# NOT this

self._camera.enabled = self.is_main_player
self._camera.enabled = false

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I’m rewritting the exact same code in GDScript and will return soon telling how it goes.

I tested the C# project. Couldn’t replicate the issue, the player wasn’t moving regardless of camera enabled in the GameScreen scene.

I could make the player move by commenting out some of the _Process code (in particular the rotation tween) and setting RawSpeed to always return the SpeedOf result, so this seems code behavior, not an engine issue. Won’t delve too much more in this issue because I didn’t properly setup my C# environment, I was editing code in Godot itself.

Thank you for pinning it down! That’ll make it easier to solve (I won’t be able to look into it myself but someone else can)

@AThousandShips Right; I’ve wrote a bit on GDScript and it the Camera2D works as expected. I’m guessing something is wrong with the C# support?

Since I’m not finding anyway to fix it, I guess I might try to move to GDScript.

@AThousandShips I’m a bit lazy to go ahead and write something in GDScript, but I’ll see if I can try a basic thing.