Search code examples
javaandroidsceneform

How do I rotate a model towards another model in scenform?


I have 6 models - one placed by the player and the rest scattered around it randomly. Currently all the models are "looking" in one direction, but I want the scattered models to be rotated so they "look" at the central model. How do I do it?

(I've tried using Quartenion.axisAngle)


Solution

  • Try with Quaternion.lookRotation() like below.

    val direction = Vector3.subtract(SCATTERED_MODEL.worldPosition, CENTRAL_NODE.worldPosition)
    SCATTERED_MODEL.worldRotation = Quaternion.lookRotation(direction, Vector3.up())