Godot Version
GODOT4.3
Question
Why can the body_set_state
function only be executed once? Regardless of how the value of Simulation_transform
changes afterwards, the transform of ball_body
seems to be fixed at the value from the first execution.
The code is as follows
func _ready() → void:
physics_space=CollisionEnvironment.physics_space
ball_body = PhysicsServer2D.body_create()
PhysicsServer2D.body_set_mode(ball_body, PhysicsServer2D.BODY_MODE_KINEMATIC)
ball_shape = shape
Simulation_transform=transform
PhysicsServer2D.body_add_shape(ball_body, ball_shape)
PhysicsServer2D.body_set_state(ball_body,PhysicsServer2D.BODY_STATE_TRANSFORM,Simulation_transform)
PhysicsServer2D.body_set_space(ball_body, physics_space)
func _physics_process(delta: float) → void:
#Changed Simulation_transform elsewhere
PhysicsServer2D.body_set_state(ball_body,PhysicsServer2D.BODY_STATE_TRANSFORM,Simulation_transform)
According to the instructions,The transform of ball_body should be changed.
void body_set_state(body: RID, state: BodyState, value: Variant)
Sets the value of a body’s state. See BodyState for the list of available states.
Note: The state change doesn’t take effect immediately. The state will change on the next physics frame.
But I cannot achieve it.HELP