If you are making a car game and wants to make the car to see the road, you can use a c_trace scan_texture to get the name of the blocks texture. But if you want to use a terrain, that won't work. The solution is to have a texture painted with defined color to define areas as your terrains second skin, or the first one if you are using the Multitexturing shader from templates.
I don't know if this is the best way, but it works fine. More or less like the Lolek's code. This code will play a sound if you are inside the red area.(You can change that.
)
And this was made by Spaz and me.
You will need a skin like this, that fits your terrain:
Here is the code:
Code:
//This code is supposed to work with PlCar01.wdl from templates because of the plCar01_entity pointer.
entity* myter;
bmap* get_skin;
var get_pixel_var;
sound sndOutOfRoad = <horn.wav>;
var TerrainVert1X;
var TerrainVert1Y;
var TerrainWidth;
var SkinSize = 512; // Give this var the size of the skin that you are going to use.
// Give this action to your terrain or copy the inside code to after
//the last line of the terrain_multi3 action from templates
Action Terrain
{
//...
myter = my;
my.skill48 = 0; //tempskill
my.skill49 = -99999999; //tempskill
WHILE(1)
{
my.skill48 += 1;
vec_for_vertex(temp,my,my.skill48);
IF(temp.x < my.skill49)
{
break;
}
my.skill49 = max(my.skill49,temp.x);
}
my.skill49 = ent_vertices(me)/my.skill48;
vec_for_vertex(my.skill50,my,1);
vec_for_vertex(my.skill53,my,ent_vertices(me));
TerrainVert1X = my.skill50;
TerrainVert1Y = my.skill51;
TerrainWidth = (my.skill53 - TerrainVert1X);
}
function get_pixel(a)
{
var DeltaX;
var DeltaY;
var c;
var d;
DeltaX = plCar01_entity.X - TerrainVert1X;
DeltaY = TerrainVert1Y - plCar01_entity.Y;
c = (SkinSize*(DeltaX/TerrainWidth));
d = (SkinSize*(DeltaY/TerrainWidth));
var format;
get_skin = bmap_for_entity(myter,a);
format = bmap_lock(get_skin,0);
get_pixel_var = pixel_for_bmap(get_skin, c, d);
bmap_unlock(get_skin);
return(get_pixel_var);
}
function SoundOfRoad() //Call this function inside you main
{
var store_pixel;
var pixel_colorAl[3];
pixel_colorAl[0] = 0;
pixel_colorAl[1] = 0;
pixel_colorAl[2] = 0;
store_pixel = 0;
while(plCar01_entity == null) { wait(1); }
while(1)
{
store_pixel = get_pixel(1);//The one is the number of your terrains skin to be used.
//The 888 is the format of the texture. Just look inside the manual
// and search for bmap_lock. There you will find the which format to use.
//It should be based on your terrain color skin. If you don't know what format is your texture,
//just open it in a image editor program and save as a format and try to see it.
pixel_to_vec(pixel_colorAl,NULL,888,store_pixel);
// This will test if the pixel color is red and play the Horn sound.
if(pixel_colorAl[0] >= 200 && pixel_colorAl[1] == 0 && pixel_colorAl[2] == 0)
{
snd_play(sndOutOfRoad,100,0);
//You can change this to make the car get back to the road or something else...
}
wait(1);
}
}
By the way... Use it at you onw risk.