playMaker

Author Topic: Rotate game object when mouse dragging left/right  (Read 4623 times)

BigHugeDave

  • Playmaker Newbie
  • *
  • Posts: 4
Rotate game object when mouse dragging left/right
« on: August 18, 2016, 08:02:30 AM »
Hello,

I'm new to Playmaker, but not new to Unity itself.  I'm a programmer by trade so I usually script everything, but I kept hearing great things about Playmaker so I wanted to give it a try.  So far it's pretty amazing, I'm very impressed.

The game I'm trying to make requires that when the player holds down the right mouse button and drags it should make a gun at the top of the screen rotate left and right (depending on which direction they are dragging the mouse).  Then when they press the left mouse button the gun will fire a bullet.

I'm at work at the moment so I can't put the screen shot of what I've tried so far, but basically I'm looking for any ideas as to how I can do such a thing with Playmaker.  I can do it with scripting, but I'd rather use Playmaker for most, if not all, of my game.

I have gone through several of the Playmaker tutorials on YouTube and on Playmaker's site, but haven't seen how to do something like this specifically, and I've tried for a couple hours already but no luck.

Any suggestions would be greatly appreciated.

Kind regards,

David

Sid

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Rotate game object when mouse dragging left/right
« Reply #1 on: August 18, 2016, 01:13:06 PM »
Hello.

Set up a state with "Get Mouse Button" set to Right and store the result.  Then under that place a "Bool Test" action and check the result Every Frame and set Is True to an event.

When that event gets triggered it will go to a new state that has a "Mouse Look" action with the Game Object set to the gun.  It will also have the two actions from the previous state, only this time they are waiting for false to go back to the original state.  You will also need a new set of actions to test for Button Left to go to a third state that will fire the weapon.  And then on from there to go back and forth between the states.

Hope that helps.

BigHugeDave

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Rotate game object when mouse dragging left/right
« Reply #2 on: August 18, 2016, 08:20:01 PM »
Thanks Sid!  I got it working somewhat, but I forgot to mention this is a 2D game, so I need to rotate the run along the Z axis, left and right, when the player is moving the mouse along the x axis.  But you gave me some really good insight, and I've almost got it working.

Thanks again.  I'll post what I have when I get it working.

Regards,

David

BigHugeDave

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Rotate game object when mouse dragging left/right
« Reply #3 on: August 19, 2016, 07:35:57 AM »
Well, it actually looks like I'm going to have to do this in code instead of using Playmaker.  It could be my lack of knowledge with Playmaker, but I don't think that's the case.

I've got this 2D game with a gun at the top of the screen.  The gun needs to rotate on the Z axis whenever the user clicks and holds the right mouse button.  So when you click and hold the right mouse button and move the mouse to the right, the gun should rotate to the right.  Same for the left, you click and hold the right mouse button and move the mouse left the gun should rotate to the left.

I also need to only allow it to rotate to a certain point and then rotation shouldn't be allowed any further.

If anyone has any other suggestions for something like this I'd appreciate it, otherwise I'll just do it in code because I know I can do it there manually.

Kind regards,

David

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rotate game object when mouse dragging left/right
« Reply #4 on: August 19, 2016, 12:24:34 PM »
Hi,
you can use "get mouse button down" and "get mouse button up" to see if your mouse button has been hold/released

Then i made a custom action you can try,
It will rotate the object towards the mouse, but it is not smooth so i added the option only to get the value.

I will try to make an action to make it able to go smooth later (no time atm)

i have also added it to the Ecosystem

BigHugeDave

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Rotate game object when mouse dragging left/right
« Reply #5 on: August 19, 2016, 06:33:19 PM »
Wow, you are far too nice, thanks so much for the custom action.  I completely forgot you can create those!

I'll try it out myself and see if there's anything more that I can do.

Cheers,

David

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rotate game object when mouse dragging left/right
« Reply #6 on: August 20, 2016, 06:10:29 AM »
Hi,
If you make some nice actions you can share them in the Share New Action section and i can add them to the Ecosystem
Btw i have updated the action on the Ecosystem
and added an offset to the action.

TomsTales

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Rotate game object when mouse dragging left/right
« Reply #7 on: November 07, 2020, 07:42:05 AM »
Just found this and still works like a charm!

One question though, what would I need to modify if I want the 2D object only rotates around itself? For example, I have a play character and when looking at rim from above, he should be able to look 360 degrees...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rotate game object when mouse dragging left/right
« Reply #8 on: November 07, 2020, 01:13:59 PM »
Hi.
you probably have setup your camera as a top view.

you will need to edit the action (or make a  new one)

and edit this line : transform.rotation = Quaternion.Euler(0, 0, angle - rotationOffset.Value);

you probably need to set it to : transform.rotation = Quaternion.Euler(0, angle - rotationOffset.Value, 0);