• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D Creating billboard rotation in 3D / Getting angle towards a point

matharoo

manualman
GameMaker Dev.
Hey! In GMS2 3D, I want to create billboard rotation where an object will keep facing the camera. I have the position of the object, and the position of the camera, and I want to get the XYZ angle from the former to the latter. It will be used in a matrix to rotate a vertex buffer.

I have tried many different things but I fail. Getting the z angle is easy enough:
Code:
camDirZ = point_direction(inst.x, inst.y, camX, camY);
I am very new to 3D and bad at math, so please explain the things you mention, possibly with example code. Thanks! :)
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Y direction (looking up/down) would be found via point_direction(0, inst.z, point_distance(inst.x, inst.y, camX, camY), camZ).
X direction (camera "roll"/rotation) can be anything you want, as it does not influence other angles.
 

matharoo

manualman
GameMaker Dev.
Y direction (looking up/down) would be found via point_direction(0, inst.z, point_distance(inst.x, inst.y, camX, camY), camZ).
X direction (camera "roll"/rotation) can be anything you want, as it does not influence other angles.
Thanks YAL! It works. I had to make the z values negative. :D
 
Top