How Do I Move An Entity???

Posted By: phmenard

How Do I Move An Entity??? - 10/26/07 00:43

In my last post I was concerned about selecting an entity in the 3d environment ... well, I solved it ... as I said I am in the process of creating an RTS game ... after I have the entity selected ... how do I move it around the terrain ... Ive tried c_move ... in many different ways ... why can't I get my objects to move??
Posted By: badapple

Re: How Do I Move An Entity??? - 10/26/07 11:36

maybe you should post your movement code so people can see what wrong
you might get a better response
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 11:53


Here is some of the code I am using ... selected is a pointer to the selected entity, temp and temp2 are globals ... I know they should be more descriptive but this is just test code, once I get it to work I make the code all pretty ... :-). The object selected does move, but very wildly ... this is not what I want.


function moveObject()
{
temp.x = mouse_pos.x;
temp.y = mouse_pos.y;
temp.z = 100;

temp2.x = selected.x; temp2.y = selected.y; temp2.z = selected.z;

while(temp.x != selected.x && temp.y != selected.y && temp.z != selected.z)
{
c_move (selected, temp2, temp, GLIDE);
wait(1);
}

}
Posted By: dennis

Re: How Do I Move An Entity??? - 10/26/07 15:01

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.
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 15:59

Didn't work at all ... first of all I keep getting errors saying that Target_X is not a member of ENTITY. I changed all the my's to the entity that is selected and got something similar to what I get with my code. HMMM with everything else in this language being relatively simple it bugs me that I can't get something as simple as a truck driving along my terrain to work.
Posted By: dennis

Re: How Do I Move An Entity??? - 10/26/07 16:09


Add that before the entity action...

"
#define Target_X skill56
#define Target_Y skill57
#define Target_Z skill58
"

and add this after vec_to_angle

"
c_move(me,my.skill1,nullvector,GLIDE + IGNORE_ME);
"
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 16:52

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.
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 16:54

in the if(vec .... ) I change them my to selected as well, but the above code doesn't show that.
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 17:16

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);
}

}
Posted By: dennis

Re: How Do I Move An Entity??? - 10/26/07 17:43


You want to move the entity like in a strategy game, don't you?
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 17:55

yes exactly ... that's what I am trying to do ... :-), I'm getting close ... I think ... lol
Posted By: dennis

Re: How Do I Move An Entity??? - 10/26/07 18:32


I can send you an example....can you give me your email?
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 18:38

yes that would be great ... send it to niceguyfallriver2000@yahoo.com, thanks !!!
Posted By: dennis

Re: How Do I Move An Entity??? - 10/26/07 19:04

Okay...I have just sent the demo...

It is just selecting and moving.
Posted By: phmenard

Re: How Do I Move An Entity??? - 10/26/07 19:08

Ok, thanks ... I'll check it out and get back to you ... :-)
© 2024 lite-C Forums