How do you make something follow something else after an action has been selected?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sakotijir2023

I’m creating an MVP and I’m stuck on a critical part of the MVP. I have an action button setup and it works but I need the player to be able to pick up the object and carry it until I hit the action button again. Effectively I need to take this object and translate it to the player’s position but then have it follow the player.

I was thinking in terms of removing it and adding it as a child or something but I’m not sure how that would work. I’m using GDScript.

I appreciate any advice!

:bust_in_silhouette: Reply From: Asthmar

(I’m assuming this is 2d, there are a few ways to go about this here is one.)

func On_Button_down(): ##buttons have a down/up signal
   get_node('Object').Follow_Player = true 
 
  func On_Button_up(): 
   get_node('Object').Follow_Player = false

Inside the Object script

 var Follow_Player = ## Store Player node here based on your tree setup
 func process_delta(): 
         if Follow_Player == true:
           global_position = Player.global_position