playMaker

Author Topic: Dragging and rotating Game Objects with mouse  (Read 9756 times)

Destide

  • Playmaker Newbie
  • *
  • Posts: 8
Dragging and rotating Game Objects with mouse
« on: March 02, 2012, 04:42:48 PM »
Hi, I'm currently making a 2d game and have hit a snag.I'm a total noob with Unity and  I can't figure out how to manipulate game objects in this case platforms with the mouse. I want to enable the player to move the platforms around to solve the puzzles of the game. Hopefully I've descrbed my problem well enough.


Thanks in advance

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Dragging and rotating Game Objects with mouse
« Reply #1 on: March 02, 2012, 05:03:19 PM »
You can get mouse movement using Get Axis or Get Axis Vector with "Mouse X" and "Mouse Y" as the axis names.

Then you can translate the platforms using Translate actions.

Take a look at PlaymakerSamples/TestLab/Input/GetAxis and GetAxisVector samples.

Also look at MouseClickToDrag.

If you need to select a platform before dragging it, you can make a small FSM on the platform with an Idle state that waits for MOUSE DOWN to enter a BeingDragged state, and goes back to idle on MOUSE UP. BeingDragged then handles the mouse input described above.
« Last Edit: March 02, 2012, 05:06:55 PM by Alex Chouls »

Destide

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Dragging and rotating Game Objects with mouse
« Reply #2 on: March 02, 2012, 06:23:13 PM »
Awesome thanks for setting me off in the right direction I'll play about and hopefully can nail it. Thanks again for your help

Destide

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Dragging and rotating Game Objects with mouse
« Reply #3 on: March 02, 2012, 06:52:32 PM »
Excellent so I got it working

I added a new FSM to my platform
Added two Get axis actions to it Named them Mouse X and Mouse Y, I then made float vairbles of the same names to store the values.
Then created a translate action using owner as the game object and Mouse X and Y as the values with space set to world.
One thing that did cause a bit of confusion was that I had to apply a bit of a multiplyer to the Get Axis actions.
Now to add the button down function and tweak the multiplyer. Hope this helps others in my pickle and thanks again Alex.

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Dragging and rotating Game Objects with mouse
« Reply #4 on: May 09, 2012, 12:32:33 AM »
You can get mouse movement using Get Axis or Get Axis Vector with "Mouse X" and "Mouse Y" as the axis names.

Then you can translate the platforms using Translate actions.

I've tried this, but for some reason the object is not moving fast as the mouse is, so it's not sticking to the exact mouse location.  I'm also using an orthographic camera if that makes a difference.

Take a look at PlaymakerSamples/TestLab/Input/GetAxis and GetAxisVector samples.

Also look at MouseClickToDrag.

Can you supply a direct link to these different examples?  Especially the MouseClickToDrag one.  I can't seem to find it.
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Dragging and rotating Game Objects with mouse
« Reply #5 on: May 09, 2012, 10:37:21 AM »
http://www.hutonggames.com/samples.php

There are lots of little test scenes in the TestLab folder.

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Dragging and rotating Game Objects with mouse
« Reply #6 on: May 10, 2012, 01:35:00 AM »
Thank you very much for that.  It really helped me get a basic drag going.  However, how do I make it so the Z value never changes?  Since I'm working with a 2D game it's important my Z values aren't changed jsut by dragging something.

The problem I'm having is that when I drag the object around, if I move my mouse really fast, it actually resets the position of the object back to where it originally was.  Not even the position of where it was last, just where it was spawned at.  Very strange.  My suspicion is that it has to do with the Z value, but I could be wrong.

As a side note, I am using 2D Toolkit.
« Last Edit: May 10, 2012, 06:50:47 PM by Disastercake »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Dragging and rotating Game Objects with mouse
« Reply #7 on: May 10, 2012, 06:42:34 PM »
I should add that looking at GET MOUSE Y and GET MOUSE X there are no options for every frame, so I'm not sure how to remove the Z axis from the vector3 variable that you'd get from a MOUSE PICK action.
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com

Disastercake

  • Full Member
  • ***
  • Posts: 101
  • www.disastercake.com
    • Disastercake
Re: Dragging and rotating Game Objects with mouse
« Reply #8 on: May 10, 2012, 06:54:40 PM »
A little bit of an update:

I just added an extra action to set the Z value to 0 and that worked, but I'm still having the issue where if I move the mouse too fast the icon just goes back to the middle of the map (figured out this wasn't just going back to where it started, but just the middle of the screen).

I also don't like this option for editing the Z value, since I may want to have an object at, say, Z=10.  I just simply don't want the Z value touched unless I specify it specifically.

Edit:
I've attached 3 screenshots:
Actions.jpg: The actions in "Start Following"
Example2.jpg: The flowchart
Example3.jpg: The actions in "Check if movable object"

When this bug occurs, the flowchart has never left "Start Following" prematuraly (though the object stops following it and appears in the center of the screen) and leaves it properly on mouse up.  I can then drag the object again, dropping it where i want.  If I move my mouse slow it works fine, but if I ever mouse it fast, it bugs out to the middle and stops following.

The bug is similar to the example MouseClickToDrag if you try to drag it off the plane (but does not repro in the MouseClickToDrag just by moving the mouse fast).
« Last Edit: May 10, 2012, 07:48:45 PM by Disastercake »
Soul Saga - Anime themed adventure RPG by Disastercake

http://www.disastercake.com