nearest wall
- darksmaster923
- Posts: 1857
- Joined: Wed Jan 03, 2007 10:32 pm
- Location: Huntington Beach, California, USA
I did it with this little piece of script:
The pawn has four 'check bones': 'check_upper', 'check_lower', 'check_feet' and 'check_head'. The script checks 18 different angles (= 'wallangle') starting from 0 radians (each is 0.3490658504 radians bigger than the previous). It checks if the distance to the wall in direction 'wallangle' is smaller than the previous distance to the nearest wall. It checks that seperately for each 'check bone'.
Finally, when the for-statement is finished, the variable called 'nearestwall' contains the distance to the nearest wall and 'nearestwalldir' contains the direction to the nearest wall (in imaginary units 0-18, where 18 is a full circle).
I hope this helps - I don't blame you if you don't understand, I can't explain it properly.
Code: Select all
nearestwall = 10000;
nearestwalldir = 0;
for tmp = 0 to 18
{
wallangle = tmp*0.3490658504;
walldist = GetCollideDistance("check_upper",10000*sin(wallangle),0,10000*cos(wallangle));
if(walldist < nearestwall)
{
nearestwall = walldist + 0;
nearestwalldir = tmp + 0;
}
walldist = GetCollideDistance("check_lower",10000*sin(wallangle),0,10000*cos(wallangle));
if(walldist < nearestwall)
{
nearestwall = walldist + 0;
nearestwalldir = tmp + 0;
}
walldist = GetCollideDistance("check_feet",10000*sin(wallangle),0,10000*cos(wallangle));
if(walldist < nearestwall)
{
nearestwall = walldist + 0;
nearestwalldir = tmp + 0;
}
walldist = GetCollideDistance("check_head",10000*sin(wallangle),0,10000*cos(wallangle));
if(walldist < nearestwall)
{
nearestwall = walldist + 0;
nearestwalldir = tmp + 0;
}
}Finally, when the for-statement is finished, the variable called 'nearestwall' contains the distance to the nearest wall and 'nearestwalldir' contains the direction to the nearest wall (in imaginary units 0-18, where 18 is a full circle).
I hope this helps - I don't blame you if you don't understand, I can't explain it properly.
Pain is only psychological.
Hi Juutis
Nice little bit of script there.
Not trying to hijack this thread, but why do you have ...10000*sin(wallangle), in GetCollideDistance?
Couldn't you just use the variable "wallangle" by itself
which is just 20 degree increments for the x value?
And you have 10000*cos(wallangle) for your y coordinate.
Wouldn't y be a fixed distance?
Do I have this wrong?
Nice little bit of script there.
Not trying to hijack this thread, but why do you have ...10000*sin(wallangle), in GetCollideDistance?
Couldn't you just use the variable "wallangle" by itself
which is just 20 degree increments for the x value?
And you have 10000*cos(wallangle) for your y coordinate.
Wouldn't y be a fixed distance?
Do I have this wrong?
It's because the X, Y and Z values are the offsets from the bone. Not angles. Then a line is traced from the bone to the point defined by the offset and if there's a wall between the points, the distance is returned. If there is no wall, 'false' is returned. So the 'sin' and 'cos' are there because of the offset and '10000*...' is there so the line will hit a wall. If it was, say, 100, walls further away than 100 texels would produce a 'false'.
And actually, the Y value is 0. 10000*cos(wallangle) is the Z value.
And actually, the Y value is 0. 10000*cos(wallangle) is the Z value.
Pain is only psychological.
- darksmaster923
- Posts: 1857
- Joined: Wed Jan 03, 2007 10:32 pm
- Location: Huntington Beach, California, USA
- darksmaster923
- Posts: 1857
- Joined: Wed Jan 03, 2007 10:32 pm
- Location: Huntington Beach, California, USA