Rotation of Transform2D resets in _integrate_forces

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

I have this code:

func _integrate_forces(state: Physics2DDirectBodyState) -> void:
	if reset:
		var tr = state.get_transform()
		tr.origin = some_pos
		position = some_pos
		tr.rotated(some_rot)
		state.set_transform(tr)
		reset = false

With this code, I can set the position of Rigidbody2D to some_pos. For some reason, I have to set the origin and the position itself to the pos, or else it will teleport back (why?). But it works. However setting the rotation of a Rigidbody2D does not work. It just resets itself to the last rotation. Any help?

:bust_in_silhouette: Reply From: magicalogic

To rotate tr, replace

tr.rotated(some_rot)

with

tr = tr.rotated(some_rot)

For some reason it rotates around (0, 0) instead of the objects position. Can you confirm this or have an idea why this might be? This line shouldn’t be the problem or? tr.origin = some_pos

ggez | 2020-12-01 14:28