playMaker

Author Topic: How to position GameObject at mouse cursor when mouse button is clicked?  (Read 10823 times)

bizilux

  • Full Member
  • ***
  • Posts: 171
hey all...

what im trying to do is this:      (at 1:46)
radial menu that opens where you clicked with right mouse button


how can i draw GameObject where right mouse button is pressed?


so far i managed to kind of setup everything up, it shows the menu, but not where cursor is... it basically always adds positive values to x and y coordinates, so thats why it doesnt open it at cursor, but always to top right part of the screen, because it adds for example 100 x and 100 y coordinates, it never subtracts

you can see first attachment of where the mouse was clicked, and where the radial menu opens up...
(i think it has to do something about "normalize" when getting X and Y coordinates...)

-------------------  check #2-4 attachments for more info -------------------

in  setup, i disable the panel

in mouse setup, i configure right mouse button, and then get X and Y of mouse

in open radial menu, i check if right mouse button was let go, and i enable panel, and i use set position action...

in close radial menu, i deactivate panel and reset position to 0,0
« Last Edit: June 14, 2013, 09:03:48 AM by bizilux »

bizilux

  • Full Member
  • ***
  • Posts: 171
no-one knows how to display game object at the location of mouse cursor?
« Last Edit: June 13, 2013, 10:31:38 AM by bizilux »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Move Get Mouse X/Y to the next state? Seems like you're idling in the Mouse Setup state and only getting the coordinates once so if the mouse moves while its in that state then the position does not get updated. There's no need to get that data until its time to activate the menu again which would make the position accurate.

Normalize converts the results to a float value thats kind of a percentage value (between 0 and 1) of the distance from the edges of the screen rather than a pixel offset.

Also make sure your object/wrapper for the menu is located at 0,0,0 so it isn't creating that object with an inherited position offset somewhere in the hierarchy.
« Last Edit: June 13, 2013, 10:39:02 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
if i move Get mouse x/y to the next state, it doesnt do anything different, because mouse position does get to "open radial menu" state

i dont need menu to radial menu to move with mouse, i just want it to "spawn" where the mouse cursor is, so i  just need X/Y position once. then you drag mouse across radial menu to pick the button that you want. so i think Get mouse X/Y is where it needs to be...

check attachments to see debug mode in action... it does go into Set position action, but that Set position action doesnt position the radial menu correctly on screen at those X/Y coordinates...

i disabled normalize, because it just puts between 0-1 values which i dont need, i need pixels, but it still doesnt spawn that menu where i want it...


im pretty sure everything is at 0.0.0   panel and main camera and 2d camera...
« Last Edit: June 13, 2013, 05:33:10 PM by bizilux »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Okay, so the thing is when you're using screen space (where the mouse is, with GUI stuff) and want to correlate that to World Space with objects in the scene you need to convert the screen space to the world space or give it a raycast from the mouse that intersects with an object then store the vector and use that as your point for the radial.

It's better, though.. To use Screen To World Point.

But it seems that this action is broken, I made an example scene but the action doesn't seem to be working on the Y axis as intended. Give it a look.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
haha fuck yea, i made it to work :)

nice one, teamwork i like that :)

the problem was, that Y axis wasnt ur UP and DOWN axis... the Z axis is UP and DOWN axis...

so i did this, and its working now :)

just F-ing nice :)

im gonna make video tutorial about it soon and put it on youtube :)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Ha! I didn't think of that, good stuff =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
ok maybe you guys are wondering how to restrict radial menu from not displaying off screen?
so that user will be able to see all buttons no matter how close to the edge he pressed the mouse button?

well check attachment :)

bizilux

  • Full Member
  • ***
  • Posts: 171
well it was working perfectly fine with cubes...

but when i try it with NGUI, its not working so perfectly fine...
i think the problem is that NGUI adds second orthographic camera, and i think that really messes things up...


check attachment one, i think the problem is in that value  SCREEN Z
----------

now check attachment 2.  everything works like it should, because the game is not maximized...
this SCREEN Z value is good, and it displays the menu where i have my mouse
----------

now check attachment 3.
screen is maximed, and therefore the menu wont show up at proper location...

in order for menu to display correctly at maximized screen size, i need to set SCREEN Z value from 450 to 780

but that is not the solution... everyone will have different screen sizes so there has to be some workaround... right?

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: How to position GameObject at mouse cursor when mouse button is clicked?
« Reply #9 on: September 11, 2013, 02:15:59 AM »
i have same problem for my GUI.

screen mouse X,Y is a value from 0 to 1
NGUI Panel make any sprite inside at position 0 centered middle of the screen
and because i use it to pan view, i can't use sceen to world because the result will not be the right position, i don't see the GUI.
i must fund the right way to define the Sprite position from -XY value to XY value
and this value depend of the screen size so it can be any value...

finally the -XY value must be egal to 0 and the XY value to 1 to fit the cursor position.
« Last Edit: September 11, 2013, 02:19:11 AM by blackant »