Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: xohmg on July 16, 2014, 08:02:00 PM

Title: 2D Mouse Pick and 2D Move Towards [SOLVED]
Post by: xohmg on July 16, 2014, 08:02:00 PM
I am having a crazy problem that seems so basic to me but yet I have been spending my last 3 days trying to fix it to no avail.

Situation is I want to simply have the player click anywhere on the 2D scene and have the player move to that location in a straight line.

Why is this so complicated. At first It wasn't working with basic playmaker. So then I found and added the 2D add-on.

Here is what I have made as major steps, tell me if I did something wrong:


I am really desperate and something so basic as a click move action I can't seem to figure it out.

Thank you in advance for your help.

JC
Title: Re: 2D Mouse Pick and 2D Move Towards
Post by: blackmoondev on July 16, 2014, 08:26:12 PM
I had exactly the same problem - I used the standard 3D Mouse Pick and it all works pretty neat - here's the screenshot of the actions I have:

https://www.dropbox.com/s/i42tv67korl41yy/Screenshot%202014-07-17%2002.24.24.png

(btw. You need to have a huge sprite with a collider on the background for it to work - took me some time to figure that out;)

Title: Re: 2D Mouse Pick and 2D Move Towards
Post by: xohmg on July 16, 2014, 08:57:42 PM
I can't seem to get it to work. I switched to a 3d Mouse pick, I put my collider on my background game object now in the default layer now (even tried separate layer) and it is not registering a picked object.

Earlier with a different combination, the object would always move to 0,0,0 point no matter where I clicked. It isn't even doing that now.

Must the background collider be a direct hit or can there be object above it? I am sending the ray cast 100 units so I find it weird that it isn't hitting it...

I tried 2D Box Collider and 3D. Nothing seems to work... I really don't know what to do...
Title: Re: 2D Mouse Pick and 2D Move Towards
Post by: blackmoondev on July 17, 2014, 05:47:04 AM
Would you be able to share the actions you have? (screenshot is cool).
Title: Re: 2D Mouse Pick and 2D Move Towards
Post by: xohmg on July 17, 2014, 05:45:32 PM
Left click sends me to the proper state, and on that state I have the following actions

(http://i.imgur.com/o2D7JXH.png?1)

(http://i.imgur.com/bxpoGRs.png?1)

I even setup a basic scene that has my player and my background. My background has a box 2d collider on it and is in a different layer then my player.

Another thing I should probably mention is that main camera is a child object of my player. This is done so that when the player moves the camera follows it. I even tried removing the camera from the player and it is still giving me a problem.

(http://i.imgur.com/heJm5q1.png?1)

Everytime I left click I can see that it enters the Left Clicked state. So that is not the issue.

I'm really running out of ideas here. I had a simple click functionality working without playmaker using this :

Code: [Select]
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;

that seemed to work just fine. Would it just be easier to implement my own custom action that returns to me a vector3? I mean I don't see why this is so hard, I really wanted to use playmaker as is and already the first thing I try to do I have to create a custom one line script.

Any more thoughts?
Title: Re: 2D Mouse Pick and 2D Move Towards
Post by: xohmg on July 21, 2014, 08:58:50 AM
Created a simple new action that returns the mouse position on screen using the Camera.main.ScreenToWorldPoint(Input.mousePosition) function. That fixed my issue.