Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNypyren

Posted 17 December 2012 - 07:26 PM

Here's what I do:

parentMatrix = the transform of the turret's base (the part that does not rotate)
targetPos = world position of the target
turretPos = world position of the turret

direction = Normalize(targetPos - turretPos);

// Optionally constrain the direction to a plane if you only want the turret piece to rotate on a plane.

direction = parentMatrix.InverseTransformDirection(direction); // convert world direction to local direction

// Generate a quaternion from the direction and local up vector. (my solution is Unity-specific using the LookRotation method)
// Interpolate the turret's orientation towards the quaternion. (my solution is Unity-specific using the RotateTowards method)

#1Nypyren

Posted 17 December 2012 - 07:26 PM

Here's what I do:

parentMatrix = the transform of the turret's base (the part that does not rotate)
targetPos = world position of the target
turretPos = world position of the turret

direction = Normalize(targetPos - turretPos);

// Optionally constrain the direction to a plane.

direction = parentMatrix.InverseTransformDirection(direction); // convert world direction to local direction

// Generate a quaternion from the direction and local up vector. (my solution is Unity-specific using the LookRotation method)
// Interpolate the turret's orientation towards the quaternion. (my solution is Unity-specific using the RotateTowards method)

PARTNERS