in the game i want to kind of pop the objects that are being spawned, first i tried to do it with straight clicking on the actual fruits, but the coordinates where the click was occuring were very far off for some reason i can't seem to figure out, now i tried to spawn a collision shape where the mouse is clicked and this is happeneing, i also want to add this to a mobile game so the mouse click would need to be replaced by touch input which i'll learn about later i suppose
#Regarding mouse click location on screen, i can't seem to maybe understand how it works or something
1 messages · Page 1 of 1 (latest)
the other way i'm trying to do it is without making those collisions and just checking where mouse click is happening
Mouse Click Position: (144, 505)
Object Position: (42.625, 43.625) Click Position: (144, 505) Distance: 472.380981445313
this was one of the output where i clicked on the object onscreen, clearly mouse click position is very very far from the object position according....again i clicked on the object
I'll be watching this thread with great interest, because I've run into very similar problems trying to use the mouse location.
Hopefully someone has an answer.
🤞 i'm just stuck on what i'm making due to dis
Are you using a subviewport?
use global_position instead of position
So you may be running into an issue where your "in world" position is not aligned with the screen/camera. If you click the top left corner of the screen, the "click" position is going to be (0,0), but in your gameworld, it is probably not
mouse position is always in global space, or screen space
there's also the thing where your nodes might be dislocated away from the origin, so your screen position does not relate to your global position
will global position be my current display or the camera window?
global position of a node is it's actual position in relation to the origin
it doesn't have anything to do with camera or window. It is just the position of anode in the game world
but mouse click wouldn't be like a node right, i've removed the collisionshape spawning
also clicking the top left of the display was actually 0,0
mouse position is the position of the mouse cursor in relation to the upper-left corner of the screen, in pixels
so maybe object's coordinates are wrong then?
maybe your screen/camera is dislocated, maybe your nodes have wrong scale, anything could be wrong
The object's coordinates are right, you're just trying to use a point in one coordinate system in another.
If you combine your click position with your camera's position, that should get you started in the right direction
(although, your camera's position is at the "center" of the screen, so think about how that might need to be taken into account)
omg i'm stupid, the objects are wrong, there's something wrong with that
the object position is always the same, sry
i think checking the top left mouse click was the perfect thing since that showed me the mouse coordinates should be correct right
Without seeing the full node structure structure it's hard to say, but try setting the position of your new objects using global_position and see what happens. Position = position relative to the parent node; Global Position = position relative to the origin of the scene
So if the container for the new objects is at 50,50, and you spawn a new collision shape and give it position (100, 100), it will show up at 150,150
but if you set it to global position 100,100, that's where it'll be
i shall make changes...
can you share your node structure, and which node you're putting these new objects under?
oh there are no nodes except a camera2d in the gamewindow
a script spawns the objects from the sides
it's just this
yeah, position is local position, it's the position in relation to the parent, global_position is in relation to the root, or origin
no it doesn't it's at 360,640 since the window is 720x1280
just seemed like the right thing to do
ok so the the objects being spawned would be child of root, and mouse click position is global position?
In this case that seems like it should do the trick
an object is a child of whichever node you add it to with add_child()
mouse position generally is the same as global_position, if the root is where it should be, and the camera is where it should be, and the root and nodes have correct scale, but sometimes that's not the case.
ok yes that should be the root then
if you need to get the mouse position in relation to some node, you can transform it using to_local() on said node
but, maybe first you need to make it global if your tree has weird scaling and translations
yes, but i think i should really check the objects positions aswell just to know everything that's happenening since there's definitely something wrong with those in the script
i will update as soon as i can
ok i might've been overcomplicating things with adding the spawned objects in an array in the game window which i wasn't fully understanding. so i simple just added _input_event to the object's script itself, seems a much simpler approach...