here my ordering of choot:
if mouseclick()=1 and MOUSE =0 and muni>0
MOUSE =1
tir=1
DEC muni,1
dec hud_bullet,1
`user wants to shoot! let's cast a ray with Newton and see if we've hit something!
x1# = camera position x() : y1# = camera position y() : z1# = camera position z()
`get a unit vector in the direction the player is facing, by moving the camera 1 unit!
move camera 1.5
x2# = camera position x() : y2# = camera position y() : z2# = camera position z()
move camera -1.5
`we will cast a ray 500 units long.
dx# = x2# - x1#
dy# = y2# - y1#
dz# = z2# - z1#
x2# = x1# + (dx# * 500.0)
y2# = y1# + (dy# * 500.0)
z2# = z1# + (dz# * 500.0)
`cast the ray. put start point in vector 1, end point in vector 2
NDB_SetVector 1, x1#, y1#, z1#
NDB_SetVector 2, x2#, y2#, z2#
dist# = NDB_NewtonWorldrayCast()
if dist# < 1.0
`something hit!
HitBody = NDB_RayCastGetBody()
castdist# = dist# * 500.0
cast_x# = x1# + (dx# * castdist#)
cast_y# = y1# + (dy# * castdist#)
cast_z# = z1# + (dz# * castdist#)
hitmass# = NDB_NewtonBodyGetMassMatrix( HitBody )
if hitmass# > 0.0
`this is a live object, give it a kick!
NDB_SetVector 1, cast_x#, cast_y#, cast_z#
NDB_SetVector 2, dx# * Player_ShootPower#, dy# * Player_ShootPower#, dz# * Player_ShootPower#, 0.0
NDB_BodyAddForceGlobal HitBody
NDB_NewtonWorldUnfreezeBody HitBody
else
`this is the background (mass=0), add a bullethole!
bullet= MakeSphere(cast_x#-(dx#*0.01),cast_y#-(dy#*0.01),cast_z#-(dz#*0.01),0.2,23.0)
rem this for the test explose
boum = NDB_RayCastGetBody(barrel_body)
if boum then end
endif
endif
endif
if mouseclick() = 0 then MOUSE = 0
here my ordering barrel:
function Makebarrel(obj,r#,h#,rx#,ry#,rz#,mass#,bpx#,bpy#,bpz#)
remstart
bpx#,bpy#,bpz#=position
rx#,ry#,rz#=rotation
R#=rayon
h#=hauteur
remend
Col = NDB_NewtonCreateCylinder( r#,h#,)
barrel_Body = NDB_NewtonCreateBody(Col)
`Set initial position and rotation
NDB_BuildMatrix rx#, ry#, rz#,bpx#,bpy#,bpz#
NDB_NewtonBodySetMatrix barrel_Body
`calculate MI for a cylinder.
NDB_CalculateMICylinderSolid mass#, R#, h#
NDB_NewtonBodySetMassMatrix barrel_Body, mass#
NDB_NewtonReleaseCollision Col
` make object cylinder obj,1
obj = FreeObject()
print_load("[ barrel.x ]",1)
load object "Media\Models\barrel\barrel.X",obj
scale object obj, h#*50.0, r#*140.0, r#*140.0
NDB_BodySetDBProData barrel_Body, obj
fix object pivot obj
NDB_NewtonBodySetDestructorCallback barrel_Body
NDB_BodySetGravity barrel_Body, 1
endfunction barrel_Body
my probléme is that barrel_body did not detecté !
help me please