playMaker

Author Topic: [SOLVED] X;Y position of the mouse ?  (Read 8907 times)

VascBogdan

  • Full Member
  • ***
  • Posts: 118
[SOLVED] X;Y position of the mouse ?
« on: January 19, 2015, 08:38:09 AM »
I just got the X and Y position of the mouse, but they are not real (they are always bigger than 0, but anyway they are not real). How can I solve it ? I use 2D so the Input To World thing doesn't seem to let me do it.
« Last Edit: January 22, 2015, 06:27:56 AM by VascBogdan »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #1 on: January 19, 2015, 08:39:41 AM »
What are you actually trying to do? Are you trying to get the mouse position in the world or screen space?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #2 on: January 19, 2015, 09:03:17 AM »
I want my object to MoveTowards the click position, so I guess it is in space.
I thought about finding the Mouse X and Mouse Y (done it) and then transform both into a Vector 2 variable (done it), but the coordinates are not what they should be.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #3 on: January 19, 2015, 09:10:45 AM »
You could probably just use a Mouse Pick for that?

You're trying to get a World Space coordinate for your character to use as a destination, while Mouse coordinates are in Screen Space.

If you already have the Mouse coordinates then you can use Screen To World Point or simply try Mouse Pick to get click point in world space against some Layer (usually a floor or invisible plane).
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #4 on: January 19, 2015, 09:57:08 AM »
I tried with Mouse Pick several times and it is not working at all.

I can store my Point to a Vector3 variable, then get the X and Y and create a Vector 2 variable by these. But, as I see in debug, it doesn't give me any coordinates, it is 0.0;0.0;0.0 . I checked Every Frame, but I don't know what to do with Raycast. The same with Mouse Pick 2D, it gives me 0.0;0.0 .
What to do ? Please tell me if you need more information, I can upload a video if needed.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #5 on: January 19, 2015, 10:12:51 AM »
Did you try Screen To World Point and the Mouse XY? Is the Mouse XY correct?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #6 on: January 19, 2015, 11:14:18 AM »
I solved the XY problem, but I get another.
When my object has to move, it move 0.5-1 on X, so a very small amount that I can't even notice, and it stops. I think you have to watch it, because I've maybe done something wrong.

https://www.youtube.com/watch?v=ZR2L1qo6M-k&feature=youtu.be


Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #7 on: January 19, 2015, 11:21:18 AM »
All Vector2 Move Towards is doing is easing a vector toward another. It's a numerical calculation over time.

Put Set Position (for the ship) in the Moving state and use the result of the Move Towards every frame.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #8 on: January 19, 2015, 11:35:27 AM »
but the Set Position is Vector 3, not Vector 2. Should I import a Vector 2 Set Position script ? Is it one ?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #9 on: January 19, 2015, 02:29:24 PM »
All positions are Transforms which are XYZ Vector3's.

Even though you're working in "2D" you're still using 3 axi for your positions. For example using the 2D scene mode you can still see depth from the front and back of the scene as your character moves around on a 2d plane. Sprites still use Transforms (XYZ)... It's all smoke and mirrors :)

A little bit further on your situation though, remember that you're working with States and in any FSM only one state can be active - its the state of the FSM... So that means when you do Vectror2 Move Towards and notice that both variables available in the action are indeed Vectors.. That means that no GameObject is affected by that action. If you want to move a game object while in this State then you must use an action that can take that vector and use it to modify the position of some GameObject.

It helps while first starting out to often take a step back and think about things, else you can get overwhelmed and forget basic ideas while you're deep in thought building gameplay.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #10 on: January 19, 2015, 03:09:02 PM »
I tried to put anything related to object position into the Moving State. When I play the game, the state proporties looks grey, like desabled. Isn't that the problem ?
It's almost one month and I still didn't make this moving thing, I tried to use the script myself too... If you don't mind, can you please show me, not necesary with pictures, what and where to put anything ?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #11 on: January 19, 2015, 03:31:56 PM »
Sure, here's a working example.

Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #12 on: January 20, 2015, 07:32:55 AM »
There is nothing in the scene. Are you sure you made it right ? There is not even a camera. I think I will understand better by an example like a scene, so if you can solve the problem, please upload it back.
Thank you.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: X;Y position of the mouse ?
« Reply #13 on: January 20, 2015, 07:41:51 AM »
Hmm, maybe because I exported it from Unity 5 beta. Odd because its worked before going from 5 to4.6.. It will be later tonight before I can redo it with 4.6.

Here are screenshots in the meantime.

Just make a floor on the same layer as your Mouse Pick (in my case, I used the Water layer for the floor) and the below should work fine for moving an object somewhere along a surface. Not sure if this would directly convert to a 2d camera/vector2 scenario without a bit of tweaking, but it shouldn't be terribly difficult.
« Last Edit: January 20, 2015, 07:46:10 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

VascBogdan

  • Full Member
  • ***
  • Posts: 118
Re: X;Y position of the mouse ?
« Reply #14 on: January 20, 2015, 08:13:52 AM »
Thank you very much man, really usefull. I will try this as soon as I come from school.

Ok, I tried it but again the same problem, but now another:
- When I click, it move to 0;0;0, the object disappear.
- When I click again, it looks like it move but again to the 0;0;0.

 I tried to increase the Z of my object, but the same. I've done exactly as you told me.

Edit:
I disabled the Look At action and the object is OK, but it still going to 0;0;0. Well, not exactly to 0;0;0, but almost (because of the Distance: 0.1). What now ?
« Last Edit: January 20, 2015, 09:45:04 AM by VascBogdan »