playMaker

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

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #15 on: October 18, 2013, 03:25:13 PM »
Ok, maybe the way is not quiete right:

Code: [Select]
     // If right mouse ORBIT
                 if (Input.GetMouseButton(1))
            {
                    xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
                    yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

                    ////////OrbitAngle

                    //Clamp the vertical axis for the orbit
                    yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
                    // set camera rotation
                    desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
                    currentRotation = transform.rotation;

As far as I can see, the Y Rotation is limited by "ClampAngle" - I cant find that in the PM actions. Another thing is, the script seems to calculat with Degrees, not Vector3 values. Maybe a similar FSM setup (with Quaternion?) will be possible?!

Thanks for support!

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #16 on: October 18, 2013, 03:46:15 PM »
Ok - for the "tilting" (the camera rotates over time in Z-Axis, when orbiting "diagonal") I´ve found a working solution (dont know, if it is good, but works):

I added a "Set Rotation" action and set Z to 0 in it.

If I just find a way to limit the Y-Axis-Rotation to 80 and -80 .. would be great ;)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Mouse X/Y to rotate a camera
« Reply #17 on: October 18, 2013, 03:48:43 PM »
You can use floats for that, inject a float for the rotations and use Float Clamp (every frame) to clamp its min and max values then you can use your input gets to Float Add that rotation.

Make sense?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #18 on: October 18, 2013, 03:59:36 PM »
hmmm, no 100% ;)

Float Clamp is pretty clear - but where and how do I "Inject" what?!

Do you mean "Vector3 add"? Sorry, I am a total noob and your answer might be right, but to "loose" for me.

I just used "Float Clamp" for MouseX Input and it works - kind of.
It prevents from flipping over, but no matter what value I type for max/min. you can always rotate near 90deg up and down. I thought, low values would restrict the X rotation...


nope.. the "clamping" seems to come from the last action I added: "Set Rotation" (Z to 0)... so, still no solution ;)

I my mind it would be like this:

Vector3 from X-axis must be clamped. But it´s no float or int, it´s a Vector kind of variable. Hmmm. So Vector must be converted to float variable to make a Vectror clamped by a float?!
« Last Edit: October 18, 2013, 04:49:50 PM by Onkelpoe »

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #19 on: October 18, 2013, 04:33:21 PM »
No "Convert Vector3 to float" action, damm it ;)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Mouse X/Y to rotate a camera
« Reply #20 on: October 18, 2013, 04:43:54 PM »
You're thinking too hard about it lol

I'll try to whip up a camera example..
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #21 on: October 18, 2013, 04:55:14 PM »
Yeah, a small example would be great !!! hehehehe... ;)

But I am still not sure about the child/parent thing... it my last setup right?


Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Mouse X/Y to rotate a camera
« Reply #22 on: October 18, 2013, 05:24:12 PM »
The parenting there is correct.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #23 on: October 18, 2013, 05:56:39 PM »
Thanks a lot Lane!

Ok, so only the Clamp problem is left - then the mouse rotate FSM will be ready..

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Mouse X/Y to rotate a camera
« Reply #24 on: October 18, 2013, 06:05:32 PM »
If you use floats then you can clamp them, its just a matter of getting the float into the rotation of the object. Thats what I was trying to say.
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 #25 on: October 18, 2013, 09:33:16 PM »
You can use "getvector3 XYZ" to make floats from a vector.

This is split into two FSMs on the Empty Parent. One FSM does Y axis mouse with unlimited rotation, not a lot of actions in it.

The X axis FSM on the other hand gets a little involved for such little pay off.
The thing is when you use the Axis vector to drive objects your only getting a snapshot of input and then it sets back to 0. Therefore you can't just clamp the X input float. You need to dive into the current rotation of the object and extract the X axis information and then set up logic to say when is too much and how to get back in the right direction.

One of your other topics was when to do everything in one FSM and when to split it up and as you can see we could have easily turned this into 3 or more FSM's. I think as you get comfortable with Playmaker you will start to know when it's better to go which route.
« Last Edit: October 19, 2013, 01:33:02 AM by redikann »

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #26 on: October 21, 2013, 12:17:03 PM »
Thank you for attaching a file - but I cant open it...

So, would you please explain, how to "dive into current location" and "extract the X axis information" ? ;)

I really need this to be fixed and want to understand it

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Get Mouse X/Y to rotate a camera
« Reply #27 on: October 21, 2013, 04:13:53 PM »
Where ever you save the scene file to on your computer, you need to drag it into a Unity project with Playmaker loaded too.

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #28 on: October 22, 2013, 02:24:37 AM »
Ok, I think I did it the way you described, but I´ll give it another try tomorrow.

May you want to explain a bit more in depth, what you mean by

"You need to dive into the current rotation of the object and extract the X axis information and then set up logic to say when is too much and how to get back in the right direction." ?

Maybe it would help me to understand this topic a bit better

Onkelpoe

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get Mouse X/Y to rotate a camera
« Reply #29 on: October 25, 2013, 04:04:29 PM »
Thx a lot, now i got "mousePlay" working and adapted it for my needs  :D

But there is one thing about it:

When reaching the X clamp, the mouse get´s stuck and it takes a bit of "moving around back & forth" to get everything working again.

I build a stand alone and it also reacts in the same way.
Any idea what is going on ?
« Last Edit: October 25, 2013, 04:09:00 PM by Onkelpoe »