playMaker

Author Topic: 2D Object Movement With Mouse  (Read 1907 times)

Phealin

  • Playmaker Newbie
  • *
  • Posts: 1
2D Object Movement With Mouse
« on: January 07, 2015, 12:24:24 AM »
Hi, I'm quite new to Playmaker but I'm learning at an alright pace, but I've hit a dead end and is in need of help, my game is a 2D side scroller and I want to be able to click on a physics object then lift it up in the air and move it around with the mouse, there are just some weird problems with that and I've tried three different ways I could think of.

1. If I use Get Mouse X and Y to store the mouse position then do so that the object I click on with Mouse Pick Event moves to the position of the mouse with Set Position it snaps to where the 0,0 of the mouse would be and then can only move within a tiny square as it can no longer move when I hit the edge of the screen with my mouse.

2. I tried using Axis but that just snaps it back to 0,0 (Which I guess makes sense)

3. I also tried to use vectors but I got lost and didnt know how to get that to work atall so that they would do what I want so if anyone could explain this to me (if that's the answer ofc) that'd be nice!

Thanks in advance!

Edit: So I've sortof found a sulloution using Mouse Pick to Store Point every frame as a Vector3 and then call that Vector 3 in a Set Position and set the Z axis to 0 to stop it from flying at the camera, but the problem is this, if I move it too far in any direction it resets position to 0,0,0.
Any thoughts why this happens?
« Last Edit: January 07, 2015, 08:27:42 AM by Phealin »

shinodan

  • Full Member
  • ***
  • Posts: 180
    • Shinozone
Re: 2D Object Movement With Mouse
« Reply #1 on: January 08, 2015, 06:28:21 AM »
Edit: I Did not read your edit and you seem to have done a similar thing to what i have described. Unfortunately i have a bit of the same problem with the window snapping back to 0,0,0 when i move the mouse to fast. But generally its okay and works. (But that's not really good enough in a game meh)

I got mouse pick to work by getting the vector3 of the mouse pointer (every frame) with an independent FSM and storing it as a global variable, then while the mouse click was down on the object i used set position, but on the object i also frose the X Axis so that the object didn't move toward or away from the camera. When the mouse click is released i ended the Set position action.

This method worked for me when i was trying to make a drag-able UI.

Like so.


Good luck :D
« Last Edit: January 08, 2015, 06:32:41 AM by shinodan »