3D point and click pathfinding

Posted By: Knuckles

3D point and click pathfinding - 04/14/07 03:27

Hello, I have been working with the program for a while now, and I'm totally catching on to this rather quickly

I've been trying to work on this movement code specifically, and code it in different parts. First, I just want the entity to move to the spot the mouse is clicked in the area (basically teleporting there, not really running along a path yet). this is what I have so far, but it's not really working right. the entity doesn't go to the same spot you click on -- it ports to various places on the map whenever you click the left button:

Code:
  				
if(mouse_left == 1) // mouse_left = Left mouse button
{

heru.x = mouse_cursor.x;
heru.y = mouse_cursor.y;
heru.z = mouse_cursor.z;

}




Now when I get ready to implement the A* pathfinding script, would I call a function from within here?
Posted By: xXxGuitar511

Re: 3D point and click pathfinding - 04/14/07 03:53

mouse_cursor returns screen corrdinates

There's a thread around here somewhere that's covered this same thing...
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/14/07 04:07

so will I need to use mouse_pos instead?

I'll check again, but I don't believe I saw the thread that discused this
Posted By: xXxGuitar511

Re: 3D point and click pathfinding - 04/14/07 04:26

no...
Posted By: tompo

Re: 3D point and click pathfinding - 04/14/07 10:02

only you need is two vectors, vec_from and vec_to
bu if you has a isometric view, you'll need vec_for_screen to create destination vector.
Posted By: Xarthor

Re: 3D point and click pathfinding - 04/14/07 14:17

Check out this thread:
http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/719028/an/0/page/0#Post719028
Posted By: xXxGuitar511

Re: 3D point and click pathfinding - 04/14/07 15:54

Not the thread I was thinking of, but even better!
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/14/07 16:54

Thank you for this! I will check it out

And no, my game isn't isometric view, however you can move the camera around.
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/15/07 22:06

ok, I don't quite understand how to implement this action script in my code. I created a new entity for the "pointer MDL" that it was calling for:

Code:
pointerMDL.z+=10;



However, I don't know how I would call this. Would the action be called once the left mouse button is clicked?
Posted By: tompo

Re: 3D point and click pathfinding - 04/15/07 22:20

On_mouse_left function();
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/15/07 23:00

Alright, I'm getting empty pointer errors from it.
I commented out pointerMDL because it kept saying 'parameter unknown' even after I declared it above.

Now it's saying that my.push = 50; is an empty pointer.

This is what I declared above the action script:

Code:
entity* heru;
entity* npc1;
entity* npc2;
entity* npc3;
entity* temp_npc;
// entity* pointerMDL; (commented out from the error)


action heru_act {heru = me; heru = my;}
action npc1_act {npc1 = me; npc1 = my;}
action npc2_act {npc2 = me; npc2 = my;}
action npc3_act {npc3 = me; npc3 = my;}


Posted By: tompo

Re: 3D point and click pathfinding - 04/15/07 23:24

but tell me... what you want to do?!
just a game with 3rd camera or isometric view where your player goes from his position to position where you click with mouse on the ground?
Posted By: tompo

Re: 3D point and click pathfinding - 04/16/07 00:03

if yes... try something like this: //not tested but should be fine
Code:
  
entity* my_target;
entity* player;

define speed, skill1;
var distance[3];
var lets_move;

function put_target
{
my_target = me;
my.passable =on;
my.invisible =on;
while(1)
{
MOUSE_POS.X = POINTER.X; MOUSE_POS.Y = POINTER.Y;
temp.x = MOUSE_POS.x;
temp.y = MOUSE_POS.y;
temp.z = 100;
vec_for_screen(temp,CAMERA);
vec_set(my.x, temp);
temp.z -= 1000;
trace_mode = IGNORE_ME + IGNORE_PASSABLE + IGNORE_SPRITES + ignore_models + use_box + scan_texture;
result = trace (my.x, temp);
my.z -= result;
wait(1);
}
}

action player_action
{
player = me; my.narrow =on;
you = ent_create("model.mdl",my.x,put_target); //f.e. small cube
my.speed = 60; //change this to your world scale
while(1)
{
distance = vec_dist(my.x,my_target.x);
if(lets_move == 1)
{
vec_set(temp,my_target.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
c_move(me,vector(my.speed *time_step *1,0,0),nullvector,GLIDE | ACTIVATE_TRIGGER | IGNORE_SPRITES | IGNORE_PASSENTS | use_box);
if(distance <= 10){lets_move =0};
}
my.tilt =0;
wait(1);
}
}

function lets_go
{
lets_move = 1;
}

on_mouse_left lets_go;


Posted By: Knuckles

Re: 3D point and click pathfinding - 04/16/07 00:06

Quote:

but tell me... what you want to do?!
just a game with 3rd camera or isometric view where your player goes from his position to position where you click with mouse on the ground?




yes, basically a standard 3D game that has point and click movement. It's not isometric, but you can move the camera around, but I want to work on this 1 step at a time first.
Posted By: tompo

Re: 3D point and click pathfinding - 04/16/07 00:16

Try use this what i wrote above.
If something is wrong... just write

You have to add some kind of gravity to your model and of'course animations.
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/16/07 15:21

Yes, I already had it attached to the model entities before.

I ran the program, however it crashes everytime the left mouse button is pressed. It keeps saying that my.passable = on; is an empty pointer.
Posted By: tompo

Re: 3D point and click pathfinding - 04/16/07 16:14

Sorry that I have no time to check it out...
but this one should be work
Code:
  
var distance_to_target;
var move_position[3]; //move vector
var my_target[3]; //target vertor
var vecTo[3]; var vecFrom[3]; var dest[3];
define _speed, skill1;
define _moving, skill2;

IFNDEF MSG_DEFS;
FONT digit_font,<digfont.pcx>,12,16;
ENDIF;
panel helper
{
digits = 20, 20, 3, digit_font, 1,player._moving;
digits = 20, 40, 3, digit_font, 1,distance_to_target;
flags REFRESH,visible;
}


Function get_target()
{
while(mouse_left == 1)
{
MOUSE_POS.X = POINTER.X; MOUSE_POS.Y = POINTER.Y;
vecFrom.X = MOUSE_POS.X;
vecFrom.Y = MOUSE_POS.Y;
vecFrom.Z = 1;// close point
vec_set(vecTo,vecFrom);
vec_for_screen(vecFrom,CAMERA);
vecTo.Z = 10000;
vec_for_screen(vecTo,CAMERA);// far point
trace(vecFrom,vecTo);// trace a line between the two points
vec_set(my_target,target);
vec_set(move_position,target);
vec_sub(move_position,player.x);
vec_to_angle(player.pan,move_position);
distance_to_target = vec_dist(player.x,my_target.x);//calculate distance
player._moving = 1;//I have to move
player.tilt = 0;
wait(1);
}
}

function player_move()
{
while(1)
{
if(player._moving == 1) //if I have to move...
{
distance_to_target = vec_dist(player.x,my_target.x);
if(distance_to_target > 45)//if target is far away...
{
vec_set(temp,my_target.x);// keep target
vec_sub(temp,player.x); // check my position
vec_to_angle(player.pan,temp);// turn to target
my._speed = 10;
}
if(distance_to_target <= 45)//if target is close
{
player._moving = 0;//I have not to move anymore
my._speed = 0;
}
}
if(player._moving == 0) //if I have not to move...
{
my._speed = 0;
wait(1);// do nothing.
}

my.tilt = 0;//stay straight
vec_set(temp,my.X);
temp.Z -= 1000;
trace_mode=IGNORE_ME+IGNORE_MODELS+ignore_passable + USE_BOX;
result = trace (my.x, temp);
my.z -= result; //keep me on the ground
c_move(me,vector(my._speed *time_step,0,0),nullvector,GLIDE | ACTIVATE_TRIGGER | IGNORE_SPRITES | IGNORE_PASSENTS | use_box);
wait(1);
}
}

action my_player
{
player = me;
MY.FAT = OFF;
MY.NARROW = ON;

mouse_range = 10000;
player_move();
}

On_mouse_left get_target;



Posted By: tompo

Re: 3D point and click pathfinding - 04/16/07 17:37

This time is working on 100%.
I've checked this out
Posted By: tompo

Re: 3D point and click pathfinding - 04/17/07 11:57

I've add a complite script which helps you in tutorials section
Posted By: Knuckles

Re: 3D point and click pathfinding - 04/18/07 00:51

Thank you so very much! it's perfect!
© 2023 lite-C Forums