• 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!

Rotating a Cone to face a target in 3D

M

Master Summoner

Guest
I have a cone model drawn in 3d at some arbitrary x,y,z. I want it to rotate to face a target at another arbitrary x,y,z coordinate.

In my game, +X is to the right, +Z is up, and +Y is forwards.
I use the rotation functions to rotate my cone:

d3d_transform_set_rotation_z(...)
d3d_transform_set_rotation_x(...)
d3d_transform_set_rotation_y(...)

But I am having trouble calculating the angles for rot_x, rot_y, and rot_z that will cause the cone to point to my target correctly.

Help would be greatly appreciated.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
In general like
Code:
d3d_transform_add_rotation_y(point_direction(0, z1, point_distance(x1, y1, x2, y2), z2));
d3d_transform_add_rotation_z(point_direction(x1, y1, x2, y2));
First you tilt the object based on angle between objects as if looking at them perpendicularly to direction between them, then you rotate on Z-axis (in XY space).
 
M

Master Summoner

Guest
I did try something similar to this, the problem is once you rotate an angle (ex "Y") the other angles ("X", "Z") are affected as well so simply finding the point_distance for y,z doesn't work correctly. After some research I believe the problem has to do with Euler angles and can be solved using the arctan2() function but I'm not very familiar with it or the process.
 
Top