playMaker

Author Topic: 2D Mouse Pick and 2D Move Towards [SOLVED]  (Read 4589 times)

xohmg

  • Playmaker Newbie
  • *
  • Posts: 7
2D Mouse Pick and 2D Move Towards [SOLVED]
« 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:

  • Added a new Layer, created an empty game objet with box collider to it that covers all of the scene.
  • Added an input manager game object.
  • In the input manager, I get mouse button down action to detect left click and then send to a new state.
  • That new state I do a Mouse Pick 2D, store the point in a vector2, layer masking on my previous layer. I also have an bool test action that tests if I hit an object or not. Technically speaking this should always be true as there is no way to not hit my game object that covers everything.
  • This final step is where I can't seem to get it right. In the new state Move Player, I have tried the Move Towards action but that takes a Vector3.

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
« Last Edit: July 21, 2014, 08:59:06 AM by xohmg »

blackmoondev

  • Playmaker Newbie
  • *
  • Posts: 4
Re: 2D Mouse Pick and 2D Move Towards
« Reply #1 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;)


xohmg

  • Playmaker Newbie
  • *
  • Posts: 7
Re: 2D Mouse Pick and 2D Move Towards
« Reply #2 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...

blackmoondev

  • Playmaker Newbie
  • *
  • Posts: 4
Re: 2D Mouse Pick and 2D Move Towards
« Reply #3 on: July 17, 2014, 05:47:04 AM »
Would you be able to share the actions you have? (screenshot is cool).

xohmg

  • Playmaker Newbie
  • *
  • Posts: 7
Re: 2D Mouse Pick and 2D Move Towards
« Reply #4 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





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.



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?

xohmg

  • Playmaker Newbie
  • *
  • Posts: 7
Re: 2D Mouse Pick and 2D Move Towards
« Reply #5 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.