1 registered members (M_D),
1,430
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How Do I Move An Entity???
[Re: phmenard]
#163477
10/26/07 15:01
10/26/07 15:01
|
Joined: Jul 2006
Posts: 150 Deutschland/Germany, nahe Hamb...
dennis
Member
|
Member
Joined: Jul 2006
Posts: 150
Deutschland/Germany, nahe Hamb...
|
You have to convert the mouse position to the 3D world position first...then you should turn the model so that it points to the position and move it relatively. Could be like this. Code:
while(1) { mouse_mode = 4; mouse_range = 10000; mouse_map = IM_MOUSE; mouse_pos.x = mouse_cursor.x; mouse_pos.y = mouse_cursor.y; Temp1[0] = mouse_pos.x; Temp1[1] = mouse_pos.y; Temp1[2] = 50; vec_for_screen(Temp1,camera); Temp2[0] = mouse_pos.x; Temp2[1] = mouse_pos.y; Temp2[2] = 5000; vec_for_screen(Temp2,camera); c_trace(Temp1,Temp2,IGNORE_PASSABLE | IGNORE_YOU); target.z += 30; vec_set(my.Target_X,target.x); if(vec_dist(my.x,my.Target_X) > 14) { my.skill1 = 5*time_step; } vec_diff(Temp,my.Target_X,my.x); Temp[2] = 0; vec_to_angle(my.pan,Temp);
}
Temp1 und Temp2 sind globale Vektoren.
|
|
|
Re: How Do I Move An Entity???
[Re: dennis]
#163480
10/26/07 16:52
10/26/07 16:52
|
Joined: Oct 2007
Posts: 27
phmenard
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 27
|
I did what you said and now the whole program crashes ... ugggg this is the complete code ... "selected" is the entity that has been selected with a left mouse click ... a right click then calls the following ...
function moveObject() { while(1){ mouse_mode = 4; mouse_range = 10000; //mouse_map = IM_MOUSE; mouse_pos.x = mouse_cursor.x; mouse_pos.y = mouse_cursor.y; Temp1.x = mouse_pos.x; Temp1.y = mouse_pos.y; Temp1.z = 50; vec_for_screen(Temp1,camera); Temp2.x = mouse_pos.x; Temp2.y = mouse_pos.y; Temp2.z = 5000; vec_for_screen(Temp2,camera); c_trace(Temp1,Temp2,IGNORE_PASSABLE | IGNORE_YOU); target.z += 30; vec_set(selected.x,target.x); if(vec_dist(my.x,my.Target_X) > 14) { selected.skill1 = 5*time_step; } vec_diff(Temp,selected.x,selected.x); Temp.y = 0; vec_to_angle(selected.pan,Temp); c_move(selected,selected.skill1,nullvector,GLIDE + IGNORE_ME); wait(1); } }
I changed the Temp variables to normal vectors, I couldn't understand why they were arrays ... Temp1[] and Temp2[] maybe I shoudn't have done that but it didn't even compile that way.
|
|
|
Re: How Do I Move An Entity???
[Re: phmenard]
#163482
10/26/07 17:16
10/26/07 17:16
|
Joined: Oct 2007
Posts: 27
phmenard
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 27
|
Ok, I'm getting close ... I moved the while() loop down the code a bit ... now the objects are moving a little better ... but go off in random directions rather than making there way to were I right click ... new code ..... any suggestions ....
function moveObject() { mouse_mode = 4; mouse_range = 10000; //mouse_map = IM_MOUSE; mouse_pos.x = mouse_cursor.x; mouse_pos.y = mouse_cursor.y; Temp1.x = selected.x; Temp1.y = selected.y; Temp1.z = 50; vec_for_screen(Temp1,camera); Temp2.x = mouse_pos.x; Temp2.y = mouse_pos.y; Temp2.z = 5000; vec_for_screen(Temp2,camera); c_trace(Temp1,Temp2,IGNORE_PASSABLE | IGNORE_YOU); target.z += 30; vec_set(selected.Target_X,target.x); while(1){ if(vec_dist(selected.x,selected.Target_X) > 14) { selected.skill1 = 5*time_step; } vec_diff(Temp,selected.Target_X,selected.x); Temp.y = 0; vec_to_angle(selected.pan,Temp); c_move(selected,selected.skill1,nullvector,GLIDE + IGNORE_ME); wait(1); } }
|
|
|
|