**How to set position of RigidBody2D to the getviewport().getmouse_position()?*
I'm making a small little sandbox sort of project and I decided I'd start with a StaticBody2D platform at the bottom of the world (which works fine). I am trying to make a script that when the mouse is clicked, it will load the ball.tscn, and then ball.instance() into the world. Then I try to set it's location to the mousePos variable, which I made as
mousePos = get_viewport().get_mouse_position()
It doesn't work when I click. I think a few times in my debugging process it DID spawn in, but it always went to 1 spot, it never went to where the mouse is.
This entire script was under the _process(delta) function because I figured you need to always check if they clicked or not and where.
The script was inside of the ball RigidBody2D inside of my game, like this:
var mousePos = getviewport().getmouseposition()
var ballScene = load("res://ball.tscn")
var newBall = ballScene.instance()
newBall.position = mousePos
As you can see in the script, I resorted to using space because when I was playing with the code to try to fix it, space sometimes did spawn one in, but again, not at the mouse's position.
Thank you for the help!