The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

So I'm looking for a good/proper way to keep a "grabbed" item at a position that's relative to the player.

I currently have a solution, but this involves moving the .position of the target object to the global_position of the player's position. I read that changing the .position inside _physics_process is bad, but I tried putting that position setting line inside _integrate_forces of the target object, but it gave wonky physics when combined with my throw logic.

Is there a better way to keep position a foreign object? I've thought of either duplicating that object and making it a child of the player, or change the parent node of the target object (which is currently the child of the "level") to the player object.

But I couldn't come up with a solution for either.

func processAction ():
    if Input.is_action_just_pressed("action1"):
        var areas = $Area2D.get_overlapping_areas()
        if (picked_item):
            # this throws the item
            picked_item.grabbed = false
            picked_item.new_impulse = Vector2(800, -300)
            print("picked item false")
            picked_item = null
        elif (areas.size()):
            picked_item = areas[0].top
            picked_item.grabbed = true
            add_child(picked_item.instance())
        pass
    elif Input.is_action_just_pressed("action2"):
        pass
    elif Input.is_action_just_pressed("action3"):
        pass
    elif Input.is_action_just_pressed("action4"):
        pass



func _physics_process(delta):
    processAction()

    if (picked_item):
        picked_item.position = $AboveHead.global_position
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.