playMaker

Author Topic: Mouse look fix  (Read 2422 times)

mrmagoo

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Mouse look fix
« on: January 14, 2014, 07:48:21 PM »
This started as a bug but then I found the source of it so I ended up fixing it myself. There is a related bug report but I figured posting it here also would be the right thing to do.

This is my first look into any playmaker code at all (I now have all of 10 mins experience with it!) so go easy on me.  ;D

The problem is that once you have used mouselook to rotate an object it will have its constraints frozen permanently.

It appears it was a piece of code that was only added because it was part of the unity code it was borrowed from. I think the code is necessary because there could be problems with other rotational effects causing the mouse control to appear buggy to the user. Exposing it as an option to the user to turn on and off is a good idea but only half the solution.

Code: [Select]
// Make the rigid body not change rotation
// TODO: Original Unity script had this. Expose as option?
if (go.rigidbody)
{
go.rigidbody.freezeRotation = true;
}

Two problems:

  • Firstly it destroys user data as an artifact which is never good as a best practice. What if I set the freezing params in a certain way for a particular purpose?
  • The second is that it leaves behind a residual and potentially unwanted after effect - that of a frozen object.

I would suggest that what should happen is:

  • Rotation params are saved on entry
  • Params are frozen if the users requires it (default:on)
  • In all cases the rotation params are set back to the way they were before

Rather than just hand this over and expect someone else to do all the work I decided to have a crack at doing this myself. :)

Because the playmaker framework is so elegant it was trivial. (assuming I got it right)

I have attached my attempt at this code. :) I hope this is correct.
« Last Edit: January 14, 2014, 07:52:54 PM by mrmagoo »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2484
  • Yup.
    • View Profile
    • Cleverous
Re: Mouse look fix
« Reply #1 on: January 14, 2014, 08:56:42 PM »
 Haven't looked at the patched action yet, but I'm assuming that they freeze the rotation of the rigidbody to prevent physics input from causing jitter or entering odd rotations that the player did not expect.

Probably best to expose it an optional check box with true default if the patch goes to build.

mrmagoo

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mouse look fix
« Reply #2 on: January 15, 2014, 02:44:03 PM »
I understand and agree with why it is there, just not with the particular implementation. (unity's fault in this case it appears)

Which is why I did exactly that in my code. :) The numbered list describing my ideal implementation is exactly what my code does. (well...I hope! ;) )
« Last Edit: January 15, 2014, 02:45:37 PM by mrmagoo »

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 296
    • View Profile
Re: Mouse look fix
« Reply #3 on: February 26, 2014, 08:11:57 AM »
I have a project that is suffering from this exact issue.  Do you know if your fix worked?  I'll try to check it out later today.