|
Re: Getting 3D-Coordinates
[Re: Yking]
#445173
08/29/14 11:16
08/29/14 11:16
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Maybe because I am using 7.5 Extra Edition? Sure is also not working because there is no Entity or something called terrain (I am only speculating this, might be wrong). You are right. The terrain entity of the example is created on the run some code lines earlier. That function computes the mouse position over a plane. It is the absolute objetive of your character. You only need to substract the global entity position to get the relative movement vector.
var speed = 10;
VECTOR vecMove;
vec_diff ( vecMove, vecMouseGround, ent.x ); //Get the movement vector
vec_normalize ( vecMove, speed * time_step ); // x = v * t;
c_move ( me, NULL, vecMove, GLIDE );
The orientation is taken from the movement vector.
ANGLE angTemp;
vec_to_angle ( angTemp, vecMove );
my.pan += clamp ( ang ( angTemp.pan - my.pan ), time_step * -0.3, time_step * 0.3 );
Last edited by txesmi; 08/29/14 11:16.
|
|
|
Re: Getting 3D-Coordinates
[Re: Yking]
#445191
08/29/14 19:46
08/29/14 19:46
|
Joined: Aug 2014
Posts: 57
Yking
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2014
Posts: 57
|
Thank you txesmi! You absolutely and fully solved my problems, and you deserve a gold medal for that ! Of course I also want to thank AceX, Reconnoiter and Superku, - you all helped a lot ! I am going to post the full working code here, in case anyone ever has a similar problem. //Code for 3D-RTS-LIKE-UNIT-MOVEMENT //Keep in mind, I use the 7.5 Extra Edition
BOOL vec_mouseground ( VECTOR *vecGround, var groundHeight ) { if ( mouse_dir3d.z == 0 ) return FALSE; var height = groundHeight - camera->z; if ( !height ) return FALSE; if ( (height>>31) != (mouse_dir3d.z>>31) ) //( sign(height) != sign(mouse_dir3d.z) ) return FALSE; vec_set ( vecGround, &mouse_dir3d ); vec_scale ( vecGround, height / mouse_dir3d.z ); vec_add ( vecGround, &camera->x ); return TRUE; }
function move_unit() { my = UnitThatIWantToMove; VECTOR vecMouseGround; while (1) { if (vec_mouseground(vecMouseGround, 200)) //The number should be the same z-height that your entity has { draw_point3d ( vecMouseGround, vector(0,255,0), 100, 30 ); var speed = 10; VECTOR vecMove; vec_diff ( vecMove, vecMouseGround, my.x ); //Get the movement vector vec_normalize ( vecMove, speed * time_step ); // x = v * t; c_move ( my, nullvector, vecMove, GLIDE ); ANGLE angTemp; vec_to_angle ( angTemp, vecMove ); my.pan += clamp ( ang ( angTemp.pan - my.pan ), time_step * -0.3, time_step * 0.3 ); } wait(1); } }
My formatting does not look too nice, but in the SED it should become more clear . Btw. all credit to this code goes to the mentioned people, but especially txesmi .
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|