1 registered members (AndrewAMD),
678
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Simpel explanation about combine c_scan and c_move
#308541
02/03/10 16:35
02/03/10 16:35
|
Joined: Mar 2009
Posts: 21
Blackspace
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 21
|
Hi I have some problems with not fully understanding about collision. Some guy gave me some advice to use c_scan and c_move. I did some research about them and the most stuff I understand. What I don't understand is how to combine them. There was a nice AUM about it but it wasn't in C-lite so it didn't work (I don't have enough experience to convert it to c-lite) What I do know is that c_scan make some area to detect stuff. But I don't know how to trigger a function. Can some one please give a single peace of code that use both c_scan and c_move by turning a model for 90degrees when he is near a wall? Thx for reading
|
|
|
Re: Simpel explanation about combine c_scan and c_move
[Re: Widi]
#308702
02/04/10 14:49
02/04/10 14:49
|
Joined: Mar 2009
Posts: 21
Blackspace
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 21
|
hmmm.. I understand what you say but I don't have the knowledge to turn it in a code. I hope someone can finish my peace of code action guard1() { while (1) { c_move(me,vector(3 * time_step, 0, 0),nullvector, GLIDE); if ???? some code when its near a wall ?? { pan += 90; } wait(1); }}
|
|
|
Re: Simpel explanation about combine c_scan and c_move
[Re: Widi]
#308707
02/04/10 15:05
02/04/10 15:05
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
The following is a mutiliation of a "c_move sample" found in some version of the manual: (It is also a fine example of what should not be done.)
#define _feetZ skill28
#define _inputH skill29
#define _inputX skill30
#define _inputY skill31
#define _inputZ skill32
#define _inputPan skill33
#define _inputTilt skill34
#define _inputRoll skill35
#define _speedX skill36 // nu
#define _speedY skill37 // nu
#define _speedZ skill38
#define _speedPan skill40
#define _speedTilt skill41
#define _speedRoll skill42
#define _bObst skill50
#define _jmp skill51
// temp vars galore
VECTOR* ph_v1 = {x=0;y=0;z=0;}
ENTITY* ph_eMe0 = NULL;
ANGLE* ph_aForceR = {pan=0;tilt=0;roll=0;}
VECTOR* ph_vForceE = {x=0;y=0;z=0;}
VECTOR* ph_vForceW = {x=0;y=0;z=0;}
VECTOR* ph_vDistE = {x=0;y=0;z=0;}
VECTOR* ph_vDistR = {x=0;y=0;z=0;}
VECTOR* ph_vDistW = {x=0;y=0;z=0;}
var ph_nFrictZ = 0;
VECTOR* cam_v1 = {x=0;y=0;z=0;}
VECTOR* ob_v1 = {x=0;y=0;z=0;}
ANGLE* ob_a1 = {pan=0;tilt=0;roll=0;}
var ob_nTrace = 0;
var e2f_obtWall(ENTITY* _e, var _nAngle, var _nDist) {
ob_a1.pan = _nAngle;
ob_a1.tilt = 0;
ob_a1.roll = 0;
vec_for_angle(ob_v1, ob_a1);
vec_normalize(ob_v1, _nDist);
ob_nTrace = c_trace(_e.x, ob_v1, IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_BOX);
return(trace_hit);
}
void e1f_new(ENTITY* _e) {
_e.min_z *= 0.5;
vec_for_min(ph_v1, _e);
_e._feetZ = ph_v1.z;
}
void e1f_move(ENTITY* _e) {
_e._inputX += _e._inputH * _e._inputX;
_e._inputY += _e._inputH * _e._inputY;
vec_set(ph_aForceR, nullvector);
ph_aForceR.pan = _e._inputPan * 5;
vec_accelerate(ph_vDistR, _e._speedPan, ph_aForceR, 0.5);
c_rotate(_e, ph_vDistR, IGNORE_PASSABLE | GLIDE);
vec_set(ph_vDistE, nullvector);
vec_set(ph_vDistW, nullvector);
ph_eMe0 = me;
me = _e;
my = _e;
vec_set(ph_v1, _e.x);
ph_v1.z -= 5000;
if (c_trace(_e.x, ph_v1, IGNORE_ME | IGNORE_PASSABLE | USE_BOX)) {
ph_vDistW.z = _e.z + _e._feetZ - target.z;
} else {
ph_vDistW.z = 0;
}
me = ph_eMe0;
my = ph_eMe0;
if (ph_vDistW.z <= 2) { // on floor?
_e._jmp = 0;
if (_e._inputZ) {
ph_vDistE.z = (_e.max_z - (_e.min_z * 2)) * _e._inputZ;
_e._jmp = 1;
}
}
ph_nFrictZ = 0.1; // default friction
if (_e._jmp != 0) { // if jumping, add friction
ph_nFrictZ = 0.9;
}
if (ph_vDistW.z > 0) {
ph_vDistW.z = clamp(ph_vDistW.z, 0, accelerate(_e._speedZ, 5, ph_nFrictZ));
} else {
_e._speedZ = 0;
}
ph_vDistE.x = 5 * _e._inputX * time_step;
ph_vDistE.y = 2 * _e._inputY * time_step;
ph_vDistE.x = sign(ph_vDistE.x) * (abs(ph_vDistE.x) + 0.5 * ph_vDistW.z);
ph_vDistW.z *= -1;
ph_eMe0 = me;
me = _e;
my = _e;
c_move(_e, ph_vDistE, ph_vDistW, IGNORE_PASSABLE | GLIDE);
me = ph_eMe0;
my = ph_eMe0;
}
// a player action
// move with wasd or arrow keys
// jump with space or key_ins
// rotate with mouse
// run with scis..shift
action pl1a() {
e1f_new(me);
while(me != NULL) {
my._inputH = key_shift * 2;
my._inputPan = mouse_force.x * -1;
my._inputX = (key_w || key_cuu) - (key_s || key_cud);
my._inputY = (key_a || key_cul) - (key_d || key_cur);
my._inputZ = (key_space || key_ins);
e1f_move(me);
// bullsh!t camera
vec_for_angle(cam_v1, my.pan);
vec_normalize(cam_v1, my.min_x * 5);
vec_add(cam_v1, my.x);
vec_set(camera.x, cam_v1);
vec_diff(cam_v1, my.x, camera.x);
vec_to_angle(camera.pan, cam_v1);
wait(1);
}
}
// ENTITY 2 action
// ENTITY turns in circles (and just by chance, turns away from an obstacle every now and again)
action e2a() {
e1f_new(me);
while(me != NULL) {
my._inputPan = 0;
my._inputX = 1;
my._bObst = e2f_obtWall(me, 0, my.max_x * 1.5); // trace every frame
if (my._bObst) {
my._inputPan = 1;
my._inputX = 0.25;
}
e1f_move(me);
wait(1);
}
}
|
|
|
Re: Simpel explanation about combine c_scan and c_move
[Re: testDummy]
#308721
02/04/10 16:35
02/04/10 16:35
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
if ???? some code when its near a wall ?? Write:
if(trace_hit)
{
// do something
}
If your model is colliding with anything, then the stuff inside those brackets will be executed.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|