It seems like you have opened this file by double-clicking on it. In order to test your build in a browser you need to load this file from a web server. You can either upload this file and the rest of the files from a Defold HTML5 bundle to a web hosting service OR host them using a local web server on your home network.
This example shows how to orient a game object to look at the target game object in 3D space. For this purpose, we created the function quat_look_rotation (also called LookRotation or looking_at in the industry). This function creates a rotation matrix from the forward and upwards vectors and then converts it to a quaternion. The function also handles the case where no upwards direction is specified, using the default (0, 1, 0) in that case.
Note: to properly apply the resulting rotation, you must remember that your game object must face backwards to the “z” axis, i.e. in Defold the “forward” direction is vector (0, 0, -1).
In this demo you can rotate the camera by holding down the mouse button. And also switch “targets” by pressing any key.
The models used in this example are from Kenney’s Prototype Kit, licensed under CC0.
Scripts
look_rotation.script
If you want to play with these examples, you can get the project on Github.
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.