playMaker

Author Topic: How do you set something with a mouse (move left/right)?  (Read 3570 times)

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
How do you set something with a mouse (move left/right)?
« on: February 02, 2016, 03:21:52 PM »
So basically, I want to use a mouse to move a paddle in breakout left and right.  I have 'get axis' and store the float in a variable.  So how would I use this to move the paddle left and right?  This has got to have been asked before,  I can do it in C# but not sure in playmaker.

Edit:
I tried using the action 'follow mouse' but it follows on X and Y.  I just needed 1 axis.  Maybe someone could modify that action to allow X, Y or both?
« Last Edit: February 02, 2016, 04:09:48 PM by wheretheidivides »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: How do you set something with a mouse (move left/right)?
« Reply #1 on: February 02, 2016, 05:39:43 PM »
Also, how do you clamp the mouse position on screen?  I have a breakout paddle that I do not want to go to the edge of the screen.  Things are normalized 0-1 but the paddle object has a x-y-z in world space.

http://answers.unity3d.com/questions/51531/restrict-the-mouse-posisition.html

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: How do you set something with a mouse (move left/right)?
« Reply #2 on: February 02, 2016, 05:42:08 PM »
Im a noob myself but ill have a go.

In the same state with get mouse x, add an action 'Set Velocity' (or 'Set Velocity 2d' if it is a 2d game or if youre using a 2d rigid body on your object)

In the set velocity action under x axis put in your variable (the variable that stored the horizontal axis).

From my understanding that should be it, but I only know this from tutorials ive done recently.

Also in case for whatever reason you dont want to use velocity there is a way i have found that is not very elegeant and probably very nooblike but:

I have done it before with an empty game object on the left and right of the screen. You need to get each of their positions into a global variable, then on the get mouse x state have a compare float, if float is under 0 go to left state, if over 0 go to right state. In both left and right state have a move towards action (left one moves towards empty on left, vice versa for right one). Ignore vertical on the move towards actions. Insert a Compare float action under the move towards in both left and right state, have the float compare sending it back to centre and right, depending on </=/> to 0.

As I said the second method is not very elegant, but does not use velocity.

Good luck, also watch some tutorials, this is the first thing most of them cover lol.

Edit:

Sorry I thought you were actually using get axis not get mouse x, ive edites the post so it makes sense now. I hope it works for you, but im now realising the mouse controls may be trickiet than simply using axis. Still check out the breakout tutorial usimg playmaker on youtube lol:
« Last Edit: February 02, 2016, 05:54:41 PM by Zeldag »

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: How do you set something with a mouse (move left/right)?
« Reply #3 on: February 02, 2016, 05:46:05 PM »
Not sure about your second question, but couldnt you restrict the paddle movement with colliders around the edge? Or does that not do it for you?

There are clamp variable actions, so maybe experiment with them until a more experienced user pitches in, as the closest ive come to clamping anything is this one float Ive tried it on...

In fact as I mentioned tutorials here is one using playmaker to make a breakout game:

« Last Edit: February 02, 2016, 05:48:05 PM by Zeldag »

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: How do you set something with a mouse (move left/right)?
« Reply #4 on: February 02, 2016, 06:43:11 PM »
The clamp issue is normalized verses world space.  If you set the paddle movement with set position then the colliders don't have an effect.  I wrote something like that in a space invaders game using javascript.


Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: How do you set something with a mouse (move left/right)?
« Reply #5 on: February 02, 2016, 08:38:58 PM »
Yeah but if you add velocity or move towards the mouse while ignoring vertical, shouldnt the colliders take effect?? I know this still dont help you clamp anything, sorry...