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

trying to get the pitch or vertical angle

Edgamer63

Member
Hello, i'm trying to get the pitch or vertical angle between two vectors. The thing is: What's going wrong?.

I've investigated, and the suposed formula to do it is:
C++:
void getAxisAngle(EntityPlayer a, EntityPlayer b, out double yaw, out double pitch){
    double deltaX = a.posX - b.posX;
    double deltaY = a.posY - b.posY;
    double deltaZ = a.posZ - b.posZ;
    yaw = atan2(deltaY,deltaX);
    pitch = asin(deltaZ / sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ));
}
Right, i understand it, and also coded into gml like this:
GML:
///pitch_from_vectors(x,y,z,x2,y2,z2)
var x_dif=argument[3]-argument[0];
var y_dif=argument[4]-argument[1];
var z_dif=argument[5]-argument[2];
return radtodeg(arcsin(z_dif)/sqrt((x_dif*x_dif)+(y_dif*y_dif)+(z_dif*z_dif)));
And i was like: oh right, it seems to be ok.

But suddenly in GM, a weird error showed to me:

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object vect

Error in function arcsin().
 at gml_Script_pitch_from_vectors (line 5) - return radtodeg(arcsin(z_dif)/sqrt((x_dif*x_dif)+(y_dif*y_dif)+(z_dif*z_dif)));
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_pitch_from_vectors (line 5)
called from - gml_Object_vect_DrawEvent_1 (line 9) - pitch=pitch_from_vectors(x,y,z,cam.x,cam.y,cam.z)
What is that? , i obviously checked if the z vars of objects were declared, and i'm sure that z's have values, and are also defined in the objects.
 

Edgamer63

Member
Oh sorry, i solved it myself, it was an operational error, and here's the solution:
GML:
///pitch_from_vectors(x,y,z,x2,y2,z2)
var x_dif=argument[3]-argument[0];
var y_dif=argument[4]-argument[1];
var z_dif=argument[5]-argument[2];
return radtodeg(arcsin(z_dif/sqrt((x_dif*x_dif)+(y_dif*y_dif)+(z_dif*z_dif))));
Anyway a useful topic ;) .
 
Top