@Nano Brain
I've updated the sound code due to a typo that threw my numbers off.
In your example you had
objoldpos(t,3)=object position x(t)
which supposed to be
objoldpos(t,3)=object position z(t)
I did not see the typo till today
Now with that x changed to a z, I do not get those unexpected sounds, and I do not need the extra speed checks.
Velocity checking works good now
here's my updated code...
hide object playerObj
position object playerObj,camera position x(),camera position y(),camera position z()
x# = object position x(playerObj)
y# = object position y(playerObj)
z# = object position z(playerObj)
set object to object orientation playerObj,cam_obj
move object playerObj, 1
`Work out x,y,z vectors by just subtracting the old position from the new position
xvec# = object position x(playerObj) - x#
yvec# = object position y(playerObj) - y#
zvec# = object position z(playerObj) - z#
for t=1 to 100
brlobj=colarr(t)
if brlobj>0
objoldpos#(brlobj,1)=object position x(brlobj)
objoldpos#(brlobj,2)=object position y(brlobj)
objoldpos#(brlobj,3)=object position z(brlobj)
endif
next t
phy update
ray = PHY RAY CAST CLOSEST SHAPE ( x#,y#,z#,xvec#,yvec#,zvec# )
if ray =1 then obj = phy get ray cast object ()
if obj>1
velx#=phy get ray cast hit point x ( )
vely#=phy get ray cast hit point y ( )
velz#=phy get ray cast hit point z ( )
show object redball
position object redball, velx#,vely#,velz#
`print "obj "+str$(obj)
else
hide object redball
endif
if mouseclick()=0 then trigger=0
if mouseclick()=1 and trigger=0
trigger=1
play sound 27
if ray =1 and obj > 1
`play sound rnd(3)+20
velx1#=newxvalue(0,camry#,5.0)
velz1#=newzvalue(0,camry#,5.0)
phy add rigid body force obj,velx1#*2000,1300+camrx#*200,velz1#*2000,velx#,vely#,velz#,1
phy add rigid body local torque obj,-1000,0,0,1
endif
endif
phy update
col = phy get collision data()
if col=1
colobja = phy get collision object a()
colobjb = phy get collision object b()
`if colobja is terrain then use colobjb instead
if colobja = 1 then colobja = colobjb
speed#=abs(sqrt((objoldpos#(colobja,1)-object position x(colobja))^2+(objoldpos#(colobja,2)-object position y(colobja))^2+(objoldpos#(colobja,3)-object position z(colobja))^2))
if speed# >0.1
soundNumb=rnd(3)+20
audiofade(cam_obj,colobja,soundNumb,100.0,300.0)
play sound soundNumb
endif
endif
Please take a look at how I ray cast and place a red ball as a visual cue to the ray cast hit point.
When I click my mouse I apply force to a barrel but they don't respond all the time.
Do you see something off, or is there a better way than I've done?
Thanks again,
If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.