This makes no sense

The code below is for resetting a block thats falling from above the screen. As soon as it hits

the 430 limit it gets set to the top again but it remains stuck, for some reason.I Verfied by putting a print statement, cant figure how the condition is becoming true repeatdely.

if position.y>430:
		position.y=0
		print("pos y=",position.y)

Where do you call this function? Post the whole script.

extends RigidBody2D
@export var minX=50

func _ready() → void:
pass # Replace with function body.

func _process(delta: float) → void:

position.x=500
if position.y>430:
	position.y=0
	print("pos y=",position.y)
	
	pass

As this is a RigidBody2D, if you need to directly change its position, you should do it in the _integrate_forces(), not _process().

Also, if this body is in a freefall, you should reset its linear_velocity, otherwise it will keep accumulating. And I guess that’s probably what happens in your case - the body accumulates so much velocity that it flies more than 430 pixels in 1 frame, so it’s always triggering your reset code.

4 Likes

thanks for the reply but i cant figure out how to use _integrate_forces, an example would be great.

2 Likes