0 registered members (),
1,321
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: smooth rotate
[Re: Loopix]
#201882
04/11/08 20:38
04/11/08 20:38
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
I don't have much time so this is quick, this is the code I use, it works but it will need adapting for your needs:
function fnct_avoid_ai() { while(me != null) { my.avoid_left = 0; my.avoid_right = 0; if (my.task != 3 && my.task != 4 && my.task != 5) { // do 'antenna' trace 1 vec_set(temp, vector (-400,0,0)); vec_rotate (temp,vector(my.pan+160,0,0)); vec_add(temp, my.x); //ent_create(ball, temp, act_ball); result = c_trace(my.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_PUSH); // do a trace and make result = to the found value if (result > 0) { //my.pan += 4; my.avoid_right = 1; } // do 'antenna' trace 2 vec_set(temp, vector (-400,0,0)); vec_rotate (temp,vector(my.pan+200,0,0)); // gets a vector for the point shown by the angle so that the 'antenna' sticks out vec_add(temp, my.x); //ent_create(ball, temp, act_ball); result = c_trace(my.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_PUSH); // do a trace and make result = to the found value if (result > 0) { my.avoid_left = 1; //my.pan -= 3; } } if(my.avoid_right == 1) { my.pan += 4; } if(my.avoid_left == 1) { my.pan -= 4; } if(my.avoid_right == 1 && my.avoid_left == 1) { my.pan += 4; } wait(1); } }
For some reason, my ambition always seems to beat my ability.
|
|
|
Re: smooth rotate
[Re: sydan]
#203194
04/20/08 10:20
04/20/08 10:20
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
HeelX, after having converted your code to c script, it turns out that was exactly what I need! I had a function that was working, but it had the stupid alpha lock thing in it. not it's so much cooler :D... my rockets finally follow the player in a nice and smooth way
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: smooth rotate
[Re: HeelX]
#205069
05/03/08 15:57
05/03/08 15:57
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
// thread (ir)relevant snippet dump // op -> ignore
var iPAN = 0;
var iSTEP = 1;
/************************************
vfPan2
ex-dump
_vSrc: src pos (my.x)
_vDest: dest pos (your.x, player.x, etc.)
_3Step:
[iPAN] = entity pan
[iSTEP] = turn step (multiplied by time)
_vTmp: a temp vector
use:
my.pan += vfPan2(my.x, player.x, vector(my.pan, 3.15, 0), temp);
or
temp.pan = vfPan2(my.x, player.x, vector(my.pan, 3.15, 0), temp);
temp.tilt = 0; temp.roll = 0;
c_rotate(me,temp,ignore_passable + ignore_passents + ignore_me + glide);
*************************************/
function vfPan2(&_vSrc ,&_vDest, &_3Step, &_vTmp) {
//vec_set(_vTmp, nullvector);
vec_diff(_vTmp, _vDest, _vSrc);
vec_to_angle(_vTmp, _vTmp);
_vTmp[0] = ang(_vTmp[0] - _3Step[iPAN]);
_vTmp[1] = abs(_vTmp[0]);
//if (_vTmp[1] < 0.10) {
//return(_vTmp[0]);
//}
_vTmp[2] = ang(min(_vTmp[1], time * _3Step[iSTEP]) * sign(_vTmp[0]));
return(_vTmp[2]);
}
|
|
|
|