Ok.. I have the force to work on the Grenade but I can't get the rotation of the grenade to match that of the player.
this is the code I use to tell the grenade what to do.
HandleGrenade:
rotate object Grenade,Player_Xangle#, Player_Yangle#, 0.0
NDB_BodyGetPosition Grenade
position object Grenade,NDB_GetVector_X(), NDB_GetVector_Y(), NDB_GetVector_Z()
movex# = 0.0
movez# = 0.0
length# = sqrt( (movex#^2)+(movez#^2) )
movex# = movex# / length#
movez# = movez# /length#
NDB_NewtonBodyGetVelocity Grenade
currentvel_x# = NDB_GetVector_X()
currentvel_y# = NDB_GetVector_Y()
currentvel_z# = NDB_GetVector_Z()
NDB_SetVector 1, currentvel_x#*0.96,currentvel_y#*1.0, currentvel_z#*0.96
NDB_NewtonBodysetVelocity Grenade
accelx# = movex#/time#
accelz# = movez#/time#
NDB_BodyGetPosition Grenade
NDB_SetVector 2, accelx#, 0.0, accelz#
NDB_BodyAddForceGlobal Grenade
speed#=currentvel_x#^2+currentvel_z#^2
if speed#>9
NDB_BodyGetPosition Grenade
epx# = NDB_GetVector_X() : epy# = NDB_GetVector_Y() : epz# = NDB_GetVector_Z()
NDB_SetVector 1, epx#, epy#, epz#
NDB_SetVector 2, epx#, epy# - 6, epz#
dist# = NDB_NewtonWorldRayCast()
endif
AccelY# = 0.0
AccelZ# = 0.0
NDB_BodyGetPosition Grenade
px# = NDB_GetVector_X() : py# = NDB_GetVector_Y() : pz# = NDB_GetVector_Z()
NDB_SetVector 1, px#, py#, pz#
NDB_SetVector 2, px#+2.5*movex#, py# - 3.9, pz#+2.5*movez#
dist# = NDB_NewtonWorldRayCast()
if dist# < 1.0
NDB_BodyGetPosition Grenade
NDB_SetVector 2, 0.0, 1.0, 0.0
NDB_BodyAddForceGlobal Grenade
endif
if shiftkey() = 1 and object visible(Grenade)=0
show object Grenade
x1# = camera position x() : y1# = camera position y() : z1# = camera position z()
`put grenade back to player after toss
NDB_BuildMatrix 0.0, 0.0, 0.0,x1#,y1#,z1#
NDB_NewtonBodySetMatrix grenade
NDB_BodyGetPosition Grenade
px# = NDB_GetVector_X() : py# = NDB_GetVector_Y() : pz# = NDB_GetVector_Z()
NDB_SetVector 1, px#, py#, pz#
NDB_SetVector 2, px#, py#-4.0, pz#
dist# = NDB_NewtonWorldRayCast()
if dist# < 4.0
AccelY# = Grenade_TossSpeed#/ time#
AccelZ# = Grenade_Force#/ time#
NDB_BodyGetPosition Grenade
NDB_SetVector 2, 0.0, AccelY#,AccelZ#
NDB_BodyAddForceGlobal Grenade
endif
endif
if object visible(Grenade)=1
`Reduce the life (time left until explosion)
CurrentLife#=(Life#-fpss#)
inc fpss#
endif
`hide grenade after times up
if CurrentLife#<=0.0 then hide object grenade : CurrentLife#=Life# : fpss#=1
`play explosion after grenade times up
if CurrentLife#<=1.0
position object 1000,px#,py#,pz#
show object 1000
play animation 1
endif
if shiftkey() = 0 and object visible(Grenade)=0
x1# = camera position x() : y1# = camera position y() : z1# = camera position z()
`put grenade back player after toss
NDB_BuildMatrix 0.0, 0.0, 0.0,x1#,y1#,z1#
NDB_NewtonBodySetMatrix grenade
endif
`if explosion is over then hide explosion object
if animation playing(1)=0 then hide object 1000
`This prevents grenade collision with player so you can toss it.
NDB_NewtonMaterialSetDefaultCollidable PlayerID,GrenadeID, 0
NDB_NewtonMaterialSetCollisionCallback PlayerID,GrenadeID
return