1 registered members (monk12),
1,487
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
steering behaviour/avoidance(opensteer)plugin
#405004
07/20/12 19:41
07/20/12 19:41
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
OP
User
|
OP
User
Joined: Mar 2012
Posts: 927
cyberspace
|
im working on a plugin to exspose functions for use in steering behaviour and collision avoidance so far i have a few functions up and running and a experemental example.. stil need to break it down into lower level functions and add as much as possible.. will upload sometime when i have the time the first (infant stage) of my opensteer plugin with a demo showing seeking persuing and avoiding behaviour ....
Compulsive compiler
|
|
|
Re: steering behaviour/avoidance(opensteer)plugin
[Re: sivan]
#405227
07/26/12 12:35
07/26/12 12:35
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
OP
User
|
OP
User
Joined: Mar 2012
Posts: 927
cyberspace
|
Opensteer so far seems cool for me and so far its been easy to expose the functions ,i test a little as i add functions..lately i have combined opensteer avoidance functions with cmove colision boxes works okay. Thanks for support you guys ,as soon as the source is up you will find that anyone can extend/alter with ease .
Compulsive compiler
|
|
|
Re: steering behaviour/avoidance(opensteer)plugin
[Re: Puppeteer]
#406854
08/31/12 10:01
08/31/12 10:01
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
hi, I just converted the scripts to A7, because sometimes I cannot use my A8 capable pc, only an ancient laptop... works fine with a bit different character movement and added animation. test.c
#include <acknex.h>
#include <default.c>
#include "entmove.c"
///////////////////////
var opst_getmaxforce(ENTITY* ent);
var opst_getspeed(ENTITY* ent);
var opst_getradius(ENTITY* ent);
var opst_getmass(ENTITY* ent);
int possible_collision_neigbours(ENTITY* ent,var time);
void opst_addent(ENTITY* ent);
void opst_persuit(ENTITY* follower_ent,ENTITY* target_ent,var time,var maxprediction);
void opst_avoid_neigbours(ENTITY* ent,var time);
void opst_seekpos(ENTITY* ent,VECTOR* pos,var time);
void opst_setmaxforce(ENTITY* ent,var maxforce);
void opst_setspeed(ENTITY* ent,var speed);
void opst_setradius(ENTITY* ent,var radius);
void opst_setmass(ENTITY* ent,var mass);
void opst_setmaxspeed(ENTITY* ent,var speed);
void opst_brake(ENTITY* ent,var rate,var time);
VECTOR* opst_predictfuturepos(ENTITY* ent,var predictiontime);
VECTOR* opst_getvelocity(ENTITY* ent);
void opst_setpos(ENTITY* ent,VECTOR* pos);
////////////////////////
VECTOR* opst_getforwardvec(ENTITY* ent);
VECTOR* opst_toavoidcloseneighbors(ENTITY* ent,var minseperationdist);
VECTOR* opst_toavoidneighbors(ENTITY* ent,var mintimetocollision);
VECTOR* opst_forpursuit(ENTITY* follower_ent,ENTITY* target_ent,var predictiontime);
VECTOR* opst_forseek(ENTITY* ent,VECTOR* pos);
void opst_applysteerforce(ENTITY* ent,VECTOR* force,var time);
int opst_iszerovec(VECTOR* force);
VECTOR* opst_incforwardvec(ENTITY* ent,VECTOR* steerforce,VECTOR* otherforce);
VECTOR* opst_getfacedir(ENTITY* ent);
var anim;
ENTITY* seeker_ent;
action seeker()
{
while(!me){wait(1);}
VECTOR* tpos;
random_seed(0);
tpos.x=random(1000);
tpos.y=random(1000);
tpos.z=0;
// set(me,PASSABLE);
opst_addent(me);
opst_setmaxspeed(me,10);
opst_setradius(me,60);
opst_setmaxforce(me,1.5);
VECTOR* steer;
while(1)
{
if(vec_dist(vector(me.x,me.y,me.z),vector(tpos.x,tpos.y,me.z))<=50)
{
tpos.x=random(1000);
tpos.y=random(1000);
tpos.z=0;
}
VECTOR* forward=opst_getforwardvec(me);
VECTOR* avoid=opst_toavoidneighbors(me,1);
VECTOR* seek =opst_forseek(me,tpos);
if(!opst_iszerovec(avoid))
{
steer=opst_incforwardvec(me,steer,avoid);
}
else
{
steer=opst_incforwardvec(me,steer,seek);
}
opst_applysteerforce(me,steer,time_step);
// opst_seekpos(me,tpos,1*time_step);
ent_faceto(my,opst_getfacedir(me),99999*time_step);
c_move(me,vector(opst_getspeed(me)*time_step,0,0),NULL,GLIDE);
opst_setpos(me,vector(me.x,me.y,me.z));
draw_point3d(opst_getfacedir(me),COLOR_GREEN,100,5);
draw_point3d(tpos,COLOR_RED,100,5);
draw_point3d(opst_predictfuturepos(me,5),COLOR_WHITE,100,5);
my.skill1+=opst_getspeed(me)*time_step;
my.skill1%= 100;
ent_animate(me,"walk",my.skill1, ANM_CYCLE);
wait(1);
}
}
action persuier()
{
while(!me){wait(1);}
// set(me,PASSABLE);
opst_addent(me);
opst_setmaxspeed(me,10);
opst_setradius(me,60);
opst_setmaxforce(me,1.5);
VECTOR* steer;
while(1)
{
if(vec_dist(vector(me.x,me.y,me.z),vector(seeker_ent.x,seeker_ent.y,me.z))<=50)
{
opst_brake(me,1,1*time_step);
}
draw_point3d(opst_predictfuturepos(seeker_ent,20),vector(0,255,255),100,5);
VECTOR* forward=opst_getforwardvec(me);
VECTOR* avoid=opst_toavoidneighbors(me,1);
//VECTOR* avoid=opst_toavoidneighbors(me,5);
//VECTOR* pursuit=opst_forseek(me,opst_predictfuturepos(seeker_ent,20));
//VECTOR* pursuit=opst_forpursuit(me,seeker_ent,20);
VECTOR* pursuit=opst_forpursuit(me,seeker_ent,1);
if(!opst_iszerovec(avoid))
{
steer=opst_incforwardvec(me,steer,avoid);
}
else
{
steer=opst_incforwardvec(me,steer,pursuit);
}
opst_applysteerforce(me,steer,time_step);
ent_faceto(my,opst_getfacedir(me),99999*time_step);
c_move(me,vector(opst_getspeed(me)*time_step,0,0),NULL,GLIDE);
opst_setpos(me,vector(me.x,me.y,me.z));
draw_point3d(opst_getfacedir(me),COLOR_GREEN,100,5);
draw_point3d(opst_predictfuturepos(me,5),COLOR_WHITE,100,5);
my.skill1+=opst_getspeed(me)*time_step;
my.skill1%= 100;
ent_animate(me,"walk",my.skill1, ANM_CYCLE);
wait(1);
}
}
action spectator()
{
while(!me){wait(1);}
// set(me,PASSABLE);
opst_addent(me);
opst_setmaxspeed(me,10);
opst_setradius(me,60);
// opst_setmaxforce(me,2);
while(1)
{
VECTOR mypos;
// ent_rotate(me,-mouse_force.x*100*time_step,0,0); // A7 remove
// camera.tilt=clamp(camera.tilt,-45,45);
// camera.tilt+=mouse_force.y*30*time_step;
if(key_w)c_move(me,vector(10*time_step,0,0),NULL,GLIDE);
if(key_s)c_move(me,vector(-10*time_step,0,0),NULL,GLIDE);
// if(key_a)c_move(me,vector(0,10*time_step,0),NULL,GLIDE);
// if(key_d)c_move(me,vector(0,-10*time_step,0),NULL,GLIDE);
if(key_a)c_rotate(me,vector(10*time_step,0,0),GLIDE);
if(key_d)c_rotate(me,vector(-10*time_step,0,0),GLIDE);
// camera.pan=my.pan;
// camera.x=me.x;
// camera.y=me.y;
// camera.z=me.z+30;
opst_setpos(me,vector(me.x,me.y,me.z));
my.skill1+=5*time_step;
my.skill1%= 100;
if(key_any) {ent_animate(me,"walk",my.skill1, ANM_CYCLE);}
else {ent_animate(me,"idle",my.skill1, ANM_CYCLE);}
wait(1);
}
}
void main()
{
level_load(NULL);
wait(4) ;
seeker_ent=ent_create("blueguard.mdl",nullvector,seeker);
vec_set(sky_color,COLOR_BLACK);
int n;
for(n=0;n<10;n++)
ent_create("redguard.mdl",vector(100+n*80,0,0),persuier);
ent_create("blueguard.mdl",vector(0,-100,0),spectator);
vec_set(camera.x,vector(1023,-590,1067));
camera.arc=90;
camera.tilt=-53;
camera.pan=135;
camera.clip_near=1;
// fps_min=60;
// fps_max=60;
//def_move();
//def_move();
def_debug();
}
entmove.c for A7
//////////////////////////////////////////////////////////////
// entmove.c - entity position and angle manipulation functions
// (c) oP group - jcl 2010 - modified by sivan 2012 for A7
//////////////////////////////////////////////////////////////
#ifndef entmove_c
#define entmove_c
// rotate an entity relative to its own orientation
function ent_rotate(ENTITY* ent,speed_pan,speed_tilt,speed_roll)
{
me = ent;
proc_kill(5);
while(speed_pan || speed_tilt || speed_roll) {
ang_rotate(ent.pan,vector(
speed_pan*time_step,
speed_tilt*time_step,
speed_roll*time_step));
wait(1);
}
}
// rotate an entity according to its skill1,2,3 values
action ent_rotor()
{
if (!my.skill1 && !my.skill2 && !my.skill3)
ent_rotate(me,2,0,0); // no skills -> just pan
else
ent_rotate(me,my.skill1,my.skill2,my.skill3);
}
//////////////////////////////////////////////////////////////////
// turn towards an absolute target angle with given angular speed
// use wait_for_my(ent_turnto) for determining when the angle is reached
function ent_turnto(ENTITY* ent,ANGLE* to,var aspeed)
{
me = ent;
proc_kill(5);
// store the "to" angle for the wait loop - it could be a temporary vector!
ANGLE atarget;
vec_set(atarget,to);
while(aspeed) {
// calculate the difference between the current and the target angle
ANGLE adiff;
ang_diff(adiff,atarget,ent.pan);
// check if we're already there
if(vec_length(adiff) <= aspeed*time_step) {
vec_set(ent.pan,atarget);
return;
}
// scale the difference angle by the angular speed,
// and add it to the entity angle
vec_normalize(adiff,aspeed*time_step);
ang_add(ent.pan,adiff);
wait(1);
}
}
// turn towards a target position with given speed
// use wait_for_my(ent_turnto) for determining when the angle is reached
function ent_faceto(ENTITY* ent,VECTOR* pos,var aspeed)
{
if(!ent || !pos) return;
VECTOR* diff = vec_diff(NULL,pos,ent.x);
vec_to_angle(diff,diff);
ent_turnto(ent,diff,aspeed);
}
//////////////////////////////////////////////////////////////////
// move to an absolute position with given speed
// use wait_for_my(ent_moveto) for determining when the position is reached
function ent_moveto(ENTITY* ent,VECTOR* pos,var speed)
{
me = ent;
proc_kill(5);
// store the "pos" vector for the wait loop - it could be a temporary vector!
VECTOR vpos;
vec_set(vpos,pos);
while(speed) {
// calculate the difference between the current and the target position
VECTOR diff;
vec_diff(diff,vpos,ent.x);
// check if we're already there
if(vec_length(diff) <= speed*time_step) {
vec_set(ent.x,vpos);
return;
}
// scale the difference vector by the speed,
// and add it to the entity position
vec_normalize(diff,speed*time_step);
vec_add(ent.x,diff);
wait(1);
}
}
// move to a relative position with given speed
// use wait_for_my(ent_moveto) for determining when the position is reached
function ent_moveby(ENTITY* ent,VECTOR* pos,var speed)
{
if(!ent || !pos) return;
ent_moveto(ent,vec_add(pos,my.x),speed);
}
//////////////////////////////////////////////////////////////////
// place an entity on the floor below
function ent_placefloor(ENTITY* ent)
{
// get the entity's feet distance
VECTOR vMin;
vec_for_min(vMin,ent);
vMin.z *= ent.scale_z;
// find the ground below the entity origin
ENTITY* old=me; me=ent;
c_trace(
vector(ent.x,ent.y,ent.z+10),
vector(ent.x,ent.y,ent.z-1000),
IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES);
me=old;
// place the lowest part (vMin.z) on the ground (hit.z)
if(HIT_TARGET) ent.z = hit.z-vMin.z;
}
// let an entity move along a closed path with given speed
function ent_movepath(ENTITY* ent,char* pathname,var speed,var mode)
{
me = ent;
proc_kill(5);
var vLastPos[3],vDir[3];
vec_set(vLastPos,ent.x);
var dist = 0;
if (pathname) path_set(ent,pathname);
while(speed)
{
// place the entity along the path
path_spline(ent,ent.x,dist);
dist += speed*time_step;
// adjust the entity to the floor
if(mode&1)
ent_placefloor(ent);
// let the entity look ahead in movement direction
if(mode&2) {
vec_diff(vDir,ent.x,vLastPos);
vec_to_angle(ent.pan,vDir);
vec_set(vLastPos,ent.x);
}
wait(1);
}
}
#endif
|
|
|
Re: steering behaviour/avoidance(opensteer)plugin
[Re: Puppeteer]
#407484
09/13/12 16:14
09/13/12 16:14
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
OP
User
|
OP
User
Joined: Mar 2012
Posts: 927
cyberspace
|
Hi guys .. A little busy and havent worked on my projects but to reply this is not a complete solution there are other functions to be added like steer to evade etc etc and the demo was simply my testbed for functions i have done ...feel free to alter or use my source this plugin and navmesh plugin ..when i find time i shall add and upload again...sivan havent tested or checked your conversion sincei dont have a7 but im sure its good and many thanks to you and 3run and others for all your help and support you guys rock ..cherrs
Compulsive compiler
|
|
|
|