I made a block (8 x 24 quants) as a map entity. Center at 12,4.
Now I try to move this block horizontaly with 8 quants per mouse click in a field with barriers around it.
The block starts hugging the left wall.
So I trace 20 quants (12+8) to the right and the left, to see if there are any obstacles.
variables;
Code:
var trace_right[3];
var trace_left[3];
var dist_left;
var dist_right;
And in a function (only movement to the right is displayed);
Code:
function move_slider_event()
{
..............
vec_set(trace_right,vector(20,0,0));
dist_right=c_trace(my.x,trace_right.x,ignore_me|use_polygon);
vec_set(trace_left,vector(20,0,0));
vec_rotate(trace_left,vector(180,0,0));
dist_left=c_trace(my.x,trace_left.x,ignore_me|use_polygon);
if(dir_right==0)
{
c_move(my,vector8,0,0),nullvector,ignore_me|use_polygon);
}
..............
}
When I look at the values of dist_right and dist_left, they never get 0, while there is no obstical at the right side, it gives a number higher then the place of the barrier.
(dist_left should be 12 to my opinion and dist_right 0)
I thought that in c_trace the second value is how far to trace, so the value dist_right should be 0, because in the trace distance there is no obstical.
But now I think that I am totaly wrong about this. Can somebody explain to me how the c_trace works???? (I have already looked in aum 56).
--------
I also tried out in the action for the block;
Code:
action slider_act
{
my.enable_stuck=on;
my.enable_block=on;
my.enable_entity=on;
my.event=move_slider_event;
...........
}
And in the function, if the block hits the wall or another entity, revers the direction;
Code:
.................
if(event_type==event_stuck||event_type==event_block)
{
beep();
if(direction==1) {direction=-1;} else {direction=1;}
}
..................
But that does not work either. When the block hits the wall, the event is not called.
Am I doing something wrong here, can somebody explain this to me????