0 votes

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?

in Engine by (68 points)

1 Answer

0 votes

To rotate tr, replace

tr.rotated(some_rot)

with

tr = tr.rotated(some_rot)
by (1,007 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.