Hello Guys!
Can I spawn a model, which is perfect on the surface (ground)?
I mean that's a bit shit...
Attachment 660
Printable View
Hello Guys!
Can I spawn a model, which is perfect on the surface (ground)?
I mean that's a bit shit...
Attachment 660
Unfortunately, no - you can't. I've encountered this several times in my own work. In COD2, the surface which will return a solid entity using bullettrace() is often under a brush/texture and you end up with models hanging in the air. In COD4, this was fixed, and you can get the angles of geometry in a map. But, not in COD2.
model should be good :P
Ah ok :/, thank you Tally
You mean maps\mp\_utility::getplant()? Yeah, been there, seen it, done it. Got the hat to testify! It's not fool-proof. It's the way the COD2 map editor can lay textures on geometry and for the "solid" parts to register below the textures. It does it with walls as well - the decals are slightly forward of the "solid" geo behind them.
This function I converted from COD4 is the best to find solid ground to spawn models on in COD2:
Code:getGroundpoint( entity )
{
trace = bullettrace( entity.origin+(0,0,10), entity.origin + (0,0,-2000), false, entity );
groundpoint = trace["position"];
finalz = groundpoint[2];
for( angleCounter = 0; angleCounter < 10; angleCounter++ )
{
angle = angleCounter / 10.0 * 360.0;
pos = entity.origin + (cos( angle ), sin( angle ), 0);
trace = bullettrace( pos+(0,0,10), pos + (0,0,-2000), false, entity );
hitpos = trace["position"];
if( hitpos[2] > finalz && hitpos[2] < groundpoint[2] + 15 )
finalz = hitpos[2];
}
return( groundpoint[0], groundpoint[1], finalz );
}
Use trace["normal"] to find the normal-vector of the surface.
That does work, and im using it in my cod4mod
Hmmm.. I tried it Tally, but it didn't worked xD
Edit: I know that I make there something wrong xD
To "align" the angles (not position), like IzNoGod said, you need the trace["normal"]:
PHP Code:
orientToNormal( normal )
{
hor_normal = ( normal[ 0 ], normal[ 1 ], 0 );
hor_length = length( hor_normal );
if ( !hor_length )
return( 0, 0, 0 );
hor_dir = vectornormalize( hor_normal );
neg_height = normal[ 2 ] * - 1;
tangent = ( hor_dir[ 0 ] * neg_height, hor_dir[ 1 ] * neg_height, hor_length );
plant_angle = vectortoangles( tangent );
//println("^6hor_normal is ", hor_normal);
//println("^6hor_length is ", hor_length);
//println("^6hor_dir is ", hor_dir);
//println("^6neg_height is ", neg_height);
//println("^6tangent is ", tangent);
//println("^6plant_angle is ", plant_angle);
return plant_angle;
}
// ... somewhere in your code...
minigun.angles = orientToNormal(trace["normal"]);
trace is undefined :DQuote:
// ... somewhere in your code...
minigun.angles = orientToNormal(trace["normal"]);
The function Kung posted is from maps\mp\_utility.gsc. It is used as part of the getPlant() function. If you do what serthy suggested, you can use the getPlant() function to find the normals of a map and spawn your turret base at the origin returned by getPlant():
Your problem then is getting the turret head/barrel to align with the turret base. In COD4, you can do that by finding the origin of the base by a tag name - for example "j_pivot":Code:plant = self maps\mp\_utility::getPlant();
turret = spawn( "script_model", plant.origin );
turret.angles = plant.angles;
But COD2 does not support getTagOrigin(). So, your problem then is to match the orign and angles of your turret barrel with that of the turret base.Code:plant = self maps\mp\_utility::getPlant();
self.turret_base = spawn( "script_model", plant.origin );
self.turret_base.angles = plant.angles;
self.turret_barrel = spawn( "script_model", self.turret_base getTagOrigin( "j_pivot" ) );
self.turret_barrel.angles = self.turret_base.angles;
WARNIG: getPlant() often spawns models below the map surface texture (the "noramal") and often at funny angles.