PDA

View Full Version : Spawn Model on ground



Loveboy
3rd March 2014, 16:55
Hello Guys!
Can I spawn a model, which is perfect on the surface (ground)?

I mean that's a bit shit...
660

Tally
3rd March 2014, 17:00
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.

Rocky
3rd March 2014, 17:00
model should be good :P

Loveboy
3rd March 2014, 17:06
Ah ok :/, thank you Tally

serthy
3rd March 2014, 17:20
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.

Huh?

couldn't you just use the stock SD bomb plant function?

Tally
3rd March 2014, 17:28
Huh?

couldn't you just use the stock SD bomb plant function?

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:


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 );
}

IzNoGoD
3rd March 2014, 17:48
Use trace["normal"] to find the normal-vector of the surface.

That does work, and im using it in my cod4mod

Tally
3rd March 2014, 17:52
Use trace["normal"] to find the normal-vector of the surface.

That does work, and im using it in my cod4mod

Yep, tried that, and again it is not fool proof.

Loveboy
3rd March 2014, 19:35
Hmmm.. I tried it Tally, but it didn't worked xD

Edit: I know that I make there something wrong xD

kung foo man
3rd March 2014, 19:53
To "align" the angles (not position), like IzNoGod said, you need the trace["normal"]:



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"]);

Loveboy
4th March 2014, 13:25
// ... somewhere in your code...
minigun.angles = orientToNormal(trace["normal"]);

trace is undefined :D

Tally
4th March 2014, 18:45
trace is undefined :D

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():


plant = self maps\mp\_utility::getPlant();
turret = spawn( "script_model", plant.origin );
turret.angles = plant.angles;


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":


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;


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.

WARNIG: getPlant() often spawns models below the map surface texture (the "noramal") and often at funny angles.