I made an example earlier on how to shoot arrows making them stick in a wall.
However the arrows left in the wall are not physics objects just any model resembling an arrow will do, i suspect you where thinking in lines of using physics objects but as BatVink states - it is a waste of resources.
sync on
sync rate 60
autocam off
Controller = 100
Model = 101
` load model and exclude it as we will clone it later
` i just use a long box for now
`Load object "arrow.x", Model
make object box Model, 10,10,150
exclude object on Model
phy start
`make wall to shoot at
make object box 1, 1000,1000,1
phy make rigid body static box 1
` position camera to the side and angle it to wiew the flightpath
position camera -1500,100,-1000
point camera 0,0,-800
` number of arrows shot
arrownumber = 0
do
text 0,0,"Press mouse button to shoot arrow, up/down keys with mouse to move camera"
` make physics go normal speed
fps# = screen fps()
if fps#
phy set fixed timing fps#/60
endif
if mouseclick() and object exist(Controller) = 0
` create controller physics object and hide it
make object sphere Controller, 10
position object Controller , 0,0,-2000
phy make rigid body dynamic sphere Controller
hide object Controller
` put controller in motion
angy# = rnd(20)-10
angx# = rnd(10)+10
force# = 200
phy set rigid body linear velocity Controller , force#*sin(angy#)*cos(angx#),force#*sin(angx#),force#*cos(angy#)*cos(angx#)
` new arrow
inc arrownumber
clone object Model + arrownumber , Model , 1
endif
` collide with wall, this has to be before we move the model, otherwise it will collide then bounce and be left in the wrong angle
` try rem this out for the arrow to bounce
while phy get collision data ( )
a = phy get collision object a ( )
b = phy get collision object b ( )
if a=1 and b=Controller
` we hit wall, delete Controller and let arrow stick in wall
phy delete rigid body Controller
delete object Controller
endif
endwhile
` just in case we miss the target , delete controller if we get below -2000 y
if object exist(Controller)
if object position y( Controller ) < -2000
phy delete rigid body Controller
delete object Controller
endif
endif
if object exist(Controller)
` Here we get the Controller objects travel angle and update the model to it
` Get horizontal angle
x1# = object position x( Controller )
x2# = object position x( Controller )-phy get rigid body linear velocity x( Controller )
z1# = object position z( Controller )
z2# = object position z( Controller )-phy get rigid body linear velocity z( Controller )
angley# = atanfull(x1#-x2#, z1#-z2#)
` Get elevation angle (note, i dont use sqrt, just the average angle).
x1# = 0
z1# = 0
z2# = (abs(phy get rigid body linear velocity x( Controller )) + abs(phy get rigid body linear velocity z( Controller )))/2
x2# = phy get rigid body linear velocity y( Controller )
anglex# = atanfull(x1#-x2#, z1#-z2#)
` rotate Model object to the angle Controller is traveling in.
` if the model goes sideways or backwards adjust angle with adjustangley# and adjustanglex#
adjustangley# = 180 : adjustanglex# = 0
xrotate object Model + arrownumber , wrapvalue(anglex# + adjustanglex# )
yrotate object Model + arrownumber , wrapvalue(angley# + adjustangley# )
` position Model at the Controllers position
position object Model + arrownumber, object position x( Controller ) , object position y( Controller ) , object position z( Controller )
endif
`move camera with up down arrow and mouse
camspeed=20
rotate camera wrapvalue(camera angle x()+mousemovey()/2),wrapvalue(camera angle y()+mousemovex()/2),0
move camera (upkey()-downkey())*camspeed
phy update
sync
loop
Regards