playMaker

Author Topic: Quaternion.LookRotation substitute??  (Read 9362 times)

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Quaternion.LookRotation substitute??
« on: May 23, 2012, 02:02:47 AM »
I am setting up a head and neck controller for a quadraped. The rigs are created in C4D. The Z axis of the joints points in the opposite direction in Unity so the forward Z axis on the head actually looks to the rear. So. I did get a HeadController working fine with a number of lookAround modes and I was transferring the scripts to Fsm's and came up short on the Quaternion LookRotation action. The deal was this. I tried every other method but finally got it to look correctly by subtracting the head position from the target position... essentially the opposite of the way it was designed to work..using LookRotation, which seemed to be the only one set up I could feed the vars to that way and get the desired rotation spit out, was used to  slerp towards depending on reaction speed.So.. How can I do this with what I have currently or can someone write a custom action for this?  I ain't got enough days in yet and spare time to figure the syntax. ;D Anybody using C4D probably has the same issues with reversed Z axis.

TIA

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Quaternion.LookRotation substitute??
« Reply #1 on: May 23, 2012, 11:51:11 AM »
Bump on this. I would like to figure this out today.. Tight deadline and all that yadda yadda bing bang boom.

TIA

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: Quaternion.LookRotation substitute??
« Reply #2 on: May 23, 2012, 12:43:35 PM »
Hi, not sure what you're asking for exactly? Quaternion.LookRotation also uses the forward vector, so it seems like you'd have the same problem...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Quaternion.LookRotation substitute??
« Reply #3 on: May 23, 2012, 02:25:10 PM »
Hi,

 I do encounter this issue a lot of time, and I think it is perfectly fine to create a rig that takes this in consideration. By that I mean, either your solution to compute the actual target by doing some vector maths, or actually attaching the head to a dummy gameObject that itself would have the forward pointing properly. you would parent the head to this gameObject ( if feasible of course).

 Bye,

 Jean

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Quaternion.LookRotation substitute??
« Reply #4 on: May 23, 2012, 03:43:58 PM »
@Alex. The deal is I have to switch object position transforms to get the angle and THEN pass the rotation as the desiredHeadRotation and Slerp from currentHeadRotation to desiredHeadRotation. The LookAt does not allow me to do that and I get a reversed vector and the head spins. Unfortunately as per Jean's comment I cannot put dummy objects in or I break the customization functionality already built into the rig. I have already severely damaged my head prior running it into math walls by using every other Quaternion function for this and an IK system, which if I did not have a reversed Z axis from a right handed rig in a left handed coordinate system game engine would have left my poor head unbruised. When I finally realized the LookRotation was the proper function as I could change the subtraction order and get the proper vector without yards of code and dummy objects I was thrilled. It took like two lines of code. Trying with other Quaternion methods left me with tangles of one time use variables and several if else if statement going to other functions and still no joy. So..it may not seem important to some folks to have this, which IS a part of the Unity API but my experience tells me that it is an alternate function from LookAt for a reason.

I hope that explains my quandry better.

Thx

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4003
  • Official Playmaker Support
    • LinkedIn
Re: Quaternion.LookRotation substitute??
« Reply #5 on: May 23, 2012, 06:52:00 PM »
So you want a Quaternion Look Rotation action...?

Just trying to understand what you want me to make... :P

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Quaternion.LookRotation substitute??
« Reply #6 on: May 23, 2012, 07:13:44 PM »
@Alex.. Yeah.. Although I am still getting a grip on all these Actions. Is there a reason there are no Quaternion actions included? There are variable storage as quaternions and rotations but they all seem to involve game objects. Due to the reversed Z axis in the rig LookRotation was the only solution as I could get rotations for looking correctly. To get a look rotation for the reversed axis you had to subtract like this
Code: [Select]
var currentHeadRotation : Quaternion = head.transform.rotation;
var desiredHeadRotation : Quaternion = Quaternion.LookRotation(head.transform.position - lookAtTarget.position);

where you reverse the usual looker and lookedAt transforms.

LookAt forces the gameObject to LookAt and the angle expressed is opposite. I only want the angle from LookRotation because to use LookAt if the object is in front of the dog he ends up looking at his arse.

Hope that makes more sense.

edit..thinking about it a bit more what I actually need is a lookAway instead of lookAt action (maybe a checkbox in the current lookAt action??)..so instead of the forward z axis looking at the object the reverse z axis is. Sounds simple but the head would flip upside down if I used the LookAt derived rotation and multiplied it by negative 1.

Thanks
Randy
« Last Edit: May 23, 2012, 08:36:07 PM by iPetProjectDev »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Quaternion.LookRotation substitute??
« Reply #7 on: October 09, 2013, 01:59:42 PM »
Hi,

 necromancy... but Jiust to keep the records. You can now have access to Quaternions methods with a set of custom actions:

https://hutonggames.fogbugz.com/default.asp?W967

bye,

 Jean