Results 1 to 3 of 3

Thread: Rotating an object towards another one.

  1. #1

    Rotating an object towards another one.

    I need help with rotating an object to face an other object
    I'm guessing this is probably basic vector math.
    Sadly, I preferred Packman to school when they were teaching us that....

    Anybody? Help!?

  2. #2
    This worked for Mark I think:
    function faceObject(targetObject)
        local sPos = self.getPosition()
        local tPos = targetObject.getPosition()
        local tyRot = math.deg(math.atan2(tPos.x - sPos.x, tPos.z - sPos.z))
        local dist = math.sqrt((tPos.x - sPos.x)^2 + (tPos.z - sPos.z)^2)
        local txRot = math.deg(math.atan2(dist, tPos.y - sPos.y))
        self.setRotation({txRot-90, tyRot, 0}) -- might need constant offsetts here like this -90
    Only setting two axis rotations, can't control the 3rd, don't want to involve rotation matrices when I can't "require" some basic libraries.
    Last edited by dzikakulka; 02-27-2018 at 06:27 AM.

  3. #3
    Works like a charm. Thank you.

Similar Threads

  1. Rotating dice with Q and E
    By Pandoomic in forum Suggestions
    Replies: 3
    Last Post: 09-22-2017, 03:49 PM
  2. Rotating too much with high latency
    By Sancho in forum Bug Reports
    Replies: 0
    Last Post: 01-11-2017, 09:51 PM
  3. Minor Rotating Bug...
    By Mark in forum Bug Reports
    Replies: 1
    Last Post: 09-01-2016, 03:43 AM
  4. Issue with Rotating Objects
    By Telsavision in forum General Discussion
    Replies: 6
    Last Post: 01-16-2016, 08:30 PM
  5. Separately rotating figures
    By Pandoomic in forum General Discussion
    Replies: 3
    Last Post: 07-07-2015, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts