Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #45334
hoelzl opened this issue Sep 4, 2017 · 6 comments

Comments

@hoelzl
Copy link
Contributor

hoelzl commented Sep 4, 2017

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

Windows 10, current master branch (6d233c6), 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

@vnen vnen added this to the 3.0 milestone Sep 13, 2017
@akien-mga
Copy link
Member

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.

@akien-mga akien-mga modified the milestones: 3.0, 3.1 Jan 8, 2018
@eespie
Copy link

eespie commented Jan 15, 2018

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
Copy link
Contributor

eon-s commented Jan 15, 2018

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
Copy link
Member

reduz commented Sep 5, 2018

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
Copy link
Contributor

eon-s commented Sep 6, 2018

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

@akien-mga akien-mga modified the milestones: 3.1, 3.2 Jan 19, 2019
@akien-mga akien-mga removed this from the 3.2 milestone Nov 26, 2019
@KoBeWi
Copy link
Member

KoBeWi commented Nov 6, 2020

Still valid in 3.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants