I'm spawning a number of identical objects in code (Area2d with sprite and collisionshape2d children). When two objects collide I'd like to be able to stop them and put them back in their pre-collision places. To do this, in each objects process function I'm storing the current position before moving to the new position. If the object collides I'm trying to restore the old position in the ...area_entered() function but it doesn't work. Collisions are being detected properly so what's going on?
func _process(delta): # get vector to mouse var mouse_vector = (get_viewport().get_mouse_position() - position) var mv_length = mouse_vector.length() old_position = position # if nearby if mv_length < 100: if monster_type == CHASER: # growl if not flagGrowled: $GrowlSound.play() flagGrowled = true # move towards mouse cursor mouse_vector = mouse_vector.normalized() position += mouse_vector * delta * SPEED else: flagGrowled = false
and in the collision handler:
func _on_Face_area_entered(area): print("Collided") position = old_position