This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote
if Input.is_key_pressed(KEY_1):
    var Item = get_node("Icon")
    var ItemD = Item.duplicate()
    ItemD.position = get_viewport().get_mouse_position()

I am trying to duplicate something on the icon but it appears really off.

Godot version 3.4
in Engine by (13 points)

Have you tried get_global_mouse_position() or checked anchors, margins and offset of the icon?

also You should try applying change to global_position instead of position

They all seem fine and get_global_mouse_position() changed nothing.

same thing happened with global_position

Also you checked Every ancestor nodes' anchors, margins, rect_position, position?

1 Answer

0 votes

Don't You have any code in "Icon" ready() function ?
What do You mean "off" ? Show print screen of that. Perhaps it is just icon is large and its origin point is corner ?

by (8,188 points)

Tried it with a different image and got the same resultI have code that constantly checks for input and if the input is detected it duplicates the sprite.

Are there no errors in console ?
Is resulting off-position the same when project is window and fullscreen ?

Same results in fullscreen and no errors in console.

Let's see if this has anything to do with duplication.
Don't duplicate, create icon anew. From Your script I can see this is a Sprite ?

var itemd =
itemd.global_position = get_mouse_global_position()

This should create icon so its top left corner is at cursor

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.