Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: VascBogdan on January 19, 2015, 08:38:09 AM

Title: [SOLVED] X;Y position of the mouse ?
Post by: VascBogdan 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.
Title: Re: X;Y position of the mouse ?
Post by: Lane 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?
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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.
Title: Re: X;Y position of the mouse ?
Post by: Lane 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).
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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.
Title: Re: X;Y position of the mouse ?
Post by: Lane on January 19, 2015, 10:12:51 AM
Did you try Screen To World Point and the Mouse XY? Is the Mouse XY correct?
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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 (https://www.youtube.com/watch?v=ZR2L1qo6M-k&feature=youtu.be)

Title: Re: X;Y position of the mouse ?
Post by: Lane 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.
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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 ?
Title: Re: X;Y position of the mouse ?
Post by: Lane 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.
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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 ?
Title: Re: X;Y position of the mouse ?
Post by: Lane on January 19, 2015, 03:31:56 PM
Sure, here's a working example.

Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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.
Title: Re: X;Y position of the mouse ?
Post by: Lane 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.
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan 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 ?
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan on January 20, 2015, 02:10:10 PM
I tried the Move Towards action in a 3D scene and it worked, but didn't try with mouse location.

Did you solve it ?
Title: Re: X;Y position of the mouse ?
Post by: Lane on January 20, 2015, 02:26:15 PM
If the hit point is always 0,0,0 then you may have forgot to assign the layers correctly, or the floor doesnt have a collider, or you're using the wrong variable as the destination, or you aren't storing the hit point from the mouse pick.
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan on January 20, 2015, 03:21:33 PM
If you have some time, please take a look at my scene. I deleted stuff not related to the problem.
If you can explain what I've done wrong, it will help me a lot in the future.
[Sorry for the archive, the unitypackage file was 10 KB bigger than the limit].
Title: Re: X;Y position of the mouse ?
Post by: VascBogdan on January 21, 2015, 09:59:42 AM
Wow. I actually solved it.
I forgot to change the lawer for the background, I thought that this is not what you meant first time.
Thank you a lot @Lane, and believe me I learned a lot from this. In the future I will pay more attention when getting advice.
I will create another topics if I have some problems, if I can do that. Again, thank's a lot and my respect :)
Title: Re: X;Y position of the mouse ?
Post by: Lane on January 21, 2015, 10:02:57 AM
Cool! Yeah don't hesitate to ask questions, thats what the forum is here for =)