Hi,
One guy ask in the forum about how to make a weapon system to use with newton vehicle.
I put the code here to help more people.
You need to the code work
1 - the newton's wdl includes in your script
2 - a weapon model to assign the code
3 - a bullet model (cam be any thing.)
You need change the code vertex number to your vertex model number.
If you use it, not forget to send me a gift
I hope you enjoy,
the code
Code:
//bullet code by Marcio Esper
//using NGD 1.51
// you need a gun entitie to set the bullet origen
//you need a bullet model
//examine the code, some things you can delet if i forget in the code
entity* projetil;
var destino[6];
var origem[6];
var final [6];
var newtonImpulseRecord[8];
function baladata(material){
var collisionType;
var body;
dll_handle = newtonHandle;
body = NewtonGetBody (my);
collisionType = my.collision_sph_box;
body = NewtonAddMapEntity (my, collisionType);
NewtonSetBodyMass (body, my.mass);
NewtonSetBodyLinearDamp (body, my.linear_drag);
NewtonSetBodyAngularDamp (body, my.angular_drag_x, my.angular_drag_y, my.angular_drag_z);
NewtonSetBodyForceAndTorque (body, ApplyGravityForceEvent);
NewtonSetBodyMaterial (body, material);
NewtonSetBodyActiveState (body, my.start_active);
vec_for_vertex(destino, torres, 130);
vec_for_vertex(origem, torres, 78);
//vec_diff (final,destino,origem); not need this
//ENT_playSOUND (torres, bum, 100); - uncoment and make a sound if you need it
// gun end of tuble point
newtonImpulseRecord[0] = destino.x;
newtonImpulseRecord[1] = destino.y;
newtonImpulseRecord[2] = destino.z;
// origin of bullet (use to determone the direction of the impulse)
newtonImpulseRecord[3] = origem.x;
newtonImpulseRecord[4] = origem.y;
newtonImpulseRecord[5] = origem.z;
// copy the bullet mass - change it to more or less distance and damage
newtonImpulseRecord[6] = 10000;
// copy the bullet speed - change like above
newtonImpulseRecord[7] = 900;
NewtonBodyAddImpulse (body, newtonImpulseRecord);
}
action bala{
projetil =me;
my.red=255;
my.green=200;
my.blue=100;
my.lightrange = 400;
my.light=on;
my.mass =10;
my.health = 20;
my.shape_factor = 0.9;
my.start_active=1;
baladata(wood_material);
}
Function tiro(){
vec_for_vertex(temp, torres, 130); //get temp the position of vertex
ent_create("balabh.mdl", temp, bala); //you need a bullet model, in this case I use balabh.mdl, you can use a little box
}
on_mouse_left = tiro();
Sorry for the terrible English,
best regards,
Marcio