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

Changes to RigidBody2D's position through script don't apply until accessing the same property again #94633

Closed
SunkenPotato1 opened this issue Jul 22, 2024 · 2 comments

Comments

@SunkenPotato1
Copy link

Tested versions

  • Reproducible in: v4.3.beta3.official [82cedc8], v4.2.stable.official [46dc277], v4.0.stable.official [92bee43], v4.0.alpha15.official [432b25d]

System information

Godot v4.2.stable - Linux Mint 21.3 (Virginia) - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 535.183.01) - Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz (8 Threads)

Issue description

When changing RigidBody2D position through script, the changed value will not apply until you call get_global_position() directly or indirectly.

If the RigidBody2D is sleeping when you change the position, it visually moves but the moment it isn't sleeping, it's position reverts to the original location before every position change

e.g. this changes the position correctly

@onready var camera_2d: Camera2D = %Camera2D

func _process(delta: float) -> void:
	if Input.is_action_just_pressed("lmb"):
		self.get_global_position()
		self.position = camera_2d.get_local_mouse_position()

but this does not

@onready var camera_2d: Camera2D = %Camera2D

func _process(delta: float) -> void:
	if Input.is_action_just_pressed("lmb"):
		self.position = camera_2d.get_local_mouse_position()

if get_global_position() is called after changing the position it sometimes works sometimes doesn't, if its called before, it works consistently

Steps to reproduce

Click anywhere on screen to set the Rigidbody2D position to the cursor position
Can uncomment "#self.get_global_position()" in the script to fix the buggy behavior

Minimal reproduction project (MRP)

bug_report.zip

@Chaosus
Copy link
Member

Chaosus commented Jul 23, 2024

You should not change the physic body position in _process. Instead, you should use _integrate_forces method.

изображение

@Chaosus
Copy link
Member

Chaosus commented Aug 4, 2024

Checked and its fixed when used _integrate_forces instead of a _process. Closed since its resolved.

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

2 participants