playMaker

Author Topic: Get Mouse X/Y to rotate a camera  (Read 15282 times)

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Get Mouse X/Y to rotate a camera
« on: October 17, 2013, 03:47:10 AM »
… so I purchased Playmaker and fiddled around with it a few hours.

There are many examples and I think, I can get it after some time.

But I am missing some tutorial or premade asset for rotating a camera around X and Y bound to mouse input on 2D screen.

I tried to setup something up with a FSM “Rotate”, got some actions (Get axis for x and y), setup 2 float variables “mouseX,Y” and so on.

Basically just like the “Q and E rotate setup” in this tutorial:

http://www.hutonggames.com/tutorials_camera_motion_and_control.php


But instead of Q,E I want to use the mouse to make the input for rotate/orbit.

Ok, there is the standard “MouseLook” script, I know. But I got Playmaker now, so I really want to build a similar function with FSMs and stuff – not just adding the script, like I would normally, when using Unity without Playmaker…

Btw. the MouseLook script is too basic, some “smoothness” is missing (like a little bit of accel/de-accel when turning and so on)

So – can someone point out, what FSM/Action/Events/Variables to setup for a “MouseLook” kind of rotate/orbit function?

I can imagine, this could be a much requested action, maybe worth a Video-Tutorial? 
(“how to get mouse-axis-input and compute it into a camera rotation and smooth it out a bit”)



 
« Last Edit: October 25, 2013, 04:07:04 PM by Onkelpoe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Mouse X/Y to rotate a camera
« Reply #1 on: October 17, 2013, 05:29:54 AM »
Hi,

 Like you said, thse camera control are so unique that, it's better to actually build it yourself then rely on a existing one that actually never really fit your needs ( some time it does tho, but not always).

 you need to cut down the problem,

-- can you watch for mouse movement? for example detect the delta mouse per frame.

if you can do that you can then inject this delta mouse movement instead of the keyboard inputs.


 Bye,

 Jean

deepcgi

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Get Mouse X/Y to rotate a camera
« Reply #2 on: October 17, 2013, 12:58:07 PM »
Ironically, I am trying to work out the exact same mechanic today, myself.   If I make any progress on the Playmaker workflow (rather than script workflow), I'll post it here.

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #3 on: October 17, 2013, 02:30:09 PM »
Ok, here is what i´ve got so far (see attachments)

I managed to get a mouse-driven rotation running - but it is no 360° unfortunately :(

So - how to get this rotation in a 360-Version? Maybe it is not possible the way, i did start this and other things like Vector/Quaternion/Euler Angles must be used?

Sorry, but i dont know...


Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #4 on: October 17, 2013, 03:29:32 PM »
I try to build the linked script in playmaker FSM - but I just dont know the right Actions to use. The ones,  posted above wont do.

Sure, I could use the script (it works perfect) - but I would prefer to build this the FSM way (if there is a way to do so):

original: http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitZoom

Another problem (besides the only 180° rotate) is, that the camera snaps instant to the position that "ScreenInput" delivers. So if you start clicking when your Cursor is in the far right screen-field (for example) this instant-snapping occurs. The camera rotates in an instant to the cursor and after that, you can go one rotation, like it should work...

Any suggestions?

« Last Edit: October 17, 2013, 03:39:18 PM by Onkelpoe »

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #5 on: October 18, 2013, 06:20:15 AM »
hmmmm, it does not seem like a "exotic" task or am i mistaking?

But the solution or way to do this with FSM(s) is too complicated or not possible? Is that the reason that topic get so little replys?
Or is it just because the userbase is not so wide?




parallel

  • Full Member
  • ***
  • Posts: 155
Re: Get Mouse X/Y to rotate a camera
« Reply #6 on: October 18, 2013, 07:45:45 AM »
I've been holding off on designing my own PM camera setup, but can see it can be a useful learning experience, though I'm probably going to opt for this package:
https://www.assetstore.unity3d.com/#/content/6867
for my orbiting needs, as I have a ton of other features that needs work too.

I don't know if your problem is exotic, but sometimes feedback is not so forthcoming, which I guess can be for a number of reasons; people are busy, it's been mentioned in other threads, the consciousness pact you have with the universe states that you have to crack some specific problems on your own, oh and yeah the user base isn't that wide- sometimes the answer will come on a silver platter, sometimes not. Keep on cracking at it.

Regarding the snapping and un-smoothness, look into curve and tween (search those words in the action browser)

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #7 on: October 18, 2013, 08:03:44 AM »
...the consciousness pact you have with the universe states that you have to crack some specific problems on your own, ...

LoLed (really) Cool man, made me smile :)

And for:

Regarding the snapping and un-smoothness, look into curve and tween (search those words in the action browser)

I´ll take a look at them. I saw some "promising" named actions under the "iTween" menu... but I was not sure, if they were only for animation with meshes or mecanim...

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Mouse X/Y to rotate a camera
« Reply #8 on: October 18, 2013, 10:54:28 AM »
Some things you will start working on you'll find there are less straightforward solutions for, thats normal and you just need to be creative and find ways around those problems.

Parallel is right too, people are busy and not always available to answer questions, often in different time zones from your own so its usually just a matter of being patient. Generally, the response to questions around here is quite fast and nearly always gets resolved quickly.

You might look into using an empty game object as a "target" object and making your camera a child of that. Then you could zoom away from it and have a nice orbit effect by rotating the wrapper. You could make the wrapper respond to linear movement and it would be the origin of your orbiting while another button would directly rotate the camera around its own axis, resulting in a pretty flexible system you could potentially make.

It looks like you're on the right track and getting along well with the system by the screenshots, so stick with it.

Also, fyi in the Action Browser you can just start typing something and it will filter results. It's at the top, for instance just type "rotate" and it will filter all of the rotate actions.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Get Mouse X/Y to rotate a camera
« Reply #9 on: October 18, 2013, 01:25:09 PM »
Ok , so here is my start with this.

First off you will probably want to parent your camera to something and then  offset the camera from it. You will want to rotate the parent or origin to make the camera appear to rotate and orbit a point in space.

Trying to help you has taught me a little something so here we go.

1. Take 2 "Get Axis Vector" actions
    Get Axis Vector1. Horizontal axis "Mouse Y" (as long as you haven't changed the  Input settings)
    Get Axis Vector2. Vertical axis "Mouse X"   (disable the other axis on both)
   
   Map both "Get Axis Vector " to the xy plane and give both of them their own 'Vector3' (mouseX,mouseY) , I used a multiply of 5.
   
2. Run both Vector3 variables thru a "Vector3 lowpass filter", .1  seems to be fine. (.05 adds more drift)
3. Use a "Rotate" action for each variable per second every frame. Set the mouseX "Rotate" to self and the mouseY "Rotate" to world.

FYI - Things don't always run as smooth playing thru the editor so try a quick 'Build and Run' to see if things are more fluid in the actual game player. ;)
« Last Edit: October 18, 2013, 01:40:21 PM by redikann »

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #10 on: October 18, 2013, 02:09:39 PM »
hmmm, that sounds a bit confusing to me:

Should the MainCamera be child or the parent?! How do it set the target of my Cam with FSM?

I got it running somehow but - the Camera get´s a Z-Rotation (I did not set one or activate it?) so it tilts while rotating.

Here is the new setup:

« Last Edit: October 18, 2013, 02:30:34 PM by Onkelpoe »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Get Mouse X/Y to rotate a camera
« Reply #11 on: October 18, 2013, 02:17:09 PM »
The Camera would be a child of an Empty. That way if you rotate the empty you also rotate the camera but the camera can be far away looking back at the empty. Its like the moon orbiting the earth. Well maybe not quite like that. ::)

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #12 on: October 18, 2013, 02:40:48 PM »
So would it be enough, to put the Cam "into" the empty like in this screenshot and set the camera a few unity "behind" it?

I am looking for a way, to limit the X-Rotation, because I dont want the camera to flip over ;)

I looked for "clamp" but the two actions I´ve found do not work for that, it seems...


redikann

  • Full Member
  • ***
  • Posts: 174
Re: Get Mouse X/Y to rotate a camera
« Reply #13 on: October 18, 2013, 02:50:58 PM »
That's the parenting, but you want the rotation to be handled by the cam target. essentially your cam might not have any logic to it. I also didn't need to make it relative back to the camtarget because the camtarget is what is actually rotating, but if that works go with it.
« Last Edit: October 18, 2013, 02:53:09 PM by redikann »

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #14 on: October 18, 2013, 03:00:07 PM »
The other way give the same result (at first tests)...

Just to be clear, you speak of "cam target" - I dont know, if I must set this relation up and if so, where?

(CamTarget is my empty GO, now with the script that was attached to the camera before)
« Last Edit: October 18, 2013, 03:07:12 PM by Onkelpoe »