0 votes

Alright, so essentially, I have an "orb" as a child of my player. I have two Position2D children of my player, labelled "rpos" and "lpos". When the cursor is to the right of the character, I want the orb to be in the position of rpos, and when the cursor is to the left of my character, I want the orb to be in the position of lpos. Here is my code:

var mpos

func _process(delta):
    mpos = get_viewport().get_mouse_position()
    if mpos.x >= 0:
        position = get_parent().get_node("r_pos").position
    if mpos.x < 0:
        position = get_parent().get_node("l_pos").position

For some reason, no matter where the mouse is, the orb is always in the position of r_pos. Could someone help me?

in Engine by (124 points)

1 Answer

0 votes

Try:

mpos = get_parent().get_local_mouse_position()

This will give you the mouse position relative to the character instead of the viewport which is what you're getting.

by (4,101 points)
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 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 webmaster@godotengine.org with your username.