Godot Version
4.2.1
Question
I was setting the camera’s position in _ready function (in c++), the code is below:
void ThirdPersonController::setup(godot::Camera3D *camera, godot::Node3D *trackingNode) {
// if (Engine::get_singleton()->is_editor_hint()) return;
if (camera && trackingNode) {
camera->set_as_top_level(true);
_trackingNode = trackingNode;
Vector3 trackingPos = _trackingNode->to_global(Vector3());
Vector3 cameraPos = trackingPos + Vector3(0.0, _height, 0.0) + maths_3d::localBackward(camera) * _startDistance;
camera->set_rotation(Vector3(_pitch, _head, 0.0));
camera->set_position(cameraPos); // The issue happens here..
_lastTrackingPosition = trackingPos;
}
}
Whatever the argument I set, the camera always stay at (0,0,0). So I attempted to debug the code, when I debug at the above code, the cameraPos in debugger is:
When I step into it and after a few steps, as the debugger enters the Node3D::set_position, the argument becomes (0,0,0), like below:
How could it be? I really don’t know how to find the problem after that.