godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.92k stars 21.15k forks source link

RigidBody2D ignores set_position when switching between MODE_RIGID and MODE_STATIC/KINEMATIC #10959

Open hoelzl opened 7 years ago

hoelzl commented 7 years ago

Operating system or device, Godot version, GPU Model and driver (if graphics related):

Windows 10, current master branch (6d233c651b21ecaef78fbb20d0365a22919b72b1), nVidia GeForce GTX 1080, driver version V385.41 (but probably not related to GPU)

Issue description:

When switching a RigidBody2D to MODE_STATIC or MODE_KINEMATIC, changing its position, and then switching back to MODE_RIGID and applying an impulse, movement starts at the position where the previous movement stopped, not at the current position.

Steps to reproduce:

In the example project, move the ball to the green area and click LMB to launch the ball. Move to the red area and click the button again to attach the ball to the mouse. When moving the mouse the ball sticks to the mouse position as expected. Click the mouse button over the red area; the ball will launch in the green area, not from its current position.

Link to minimal example project:

2D-Physics.zip

akien-mga commented 6 years ago

We have now entered release freeze for Godot 3.0 and want to focus only on release critical issues for that milestone. Therefore, we're moving this issue to the 3.1 milestone, though a fix may be made available for a 3.0.x maintenance release after it has been tested in the master branch during 3.1 development. If you consider that this issue is critical enough to warrant blocking the 3.0 release until fixed, please comment so that we can assess it more in-depth.

eespie commented 6 years ago

I found a way to workaround this problem:

After setting the position/rotation you want, keep the corresponding transform. position = launch_position ball_transform = get_transform()

Then in the _integrate_forces(state) function apply the transform to the state. state.set_transform(ball_transform)

ball.gd.zip

eon-s commented 6 years ago

Setting position on a CollisionObject should set the state transform too, then? (I wonder if that could solve some issues on other objects, like moving areas)

reduz commented 6 years ago

This will not work because position is not sent immediately to physics when you change to staticbody, but the use case is really weird, I wonder if its worth working around it somehow to make it work

eon-s commented 6 years ago

I can think of many use cases for teleporting bodies in any mode, state access should be easier (and safe).

KoBeWi commented 4 years ago

Still valid in 3.2.3