Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#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