imekon,
Hope you don't mind a couple changes as I was playing with your code.
I added mass to the bullets and the boxes, but it seems more fun if commented out. Also, the controller box
was not positioned on the player_object,
so I changed that line. Anyhow, a good code example, and I have not seen your bug, either.
#constant player_object = 100
#constant bullet_velocity = 1000
type TBullet
id
start
endtype
global nObjectIndex = 0
global nBulletIndex = 1000
global fspeed as float = 5.0
global fturn as float = 0.03
global oldcamx as float
global oldcamy as float
global camx as float
global camy as float
randomize timer()
phy start
autocam off
phy set gravity 0, -9.8, 0
sync on
sync rate 60
backdrop off
set display mode 1024, 768, 32
set camera range 0.5, 35000
hide mouse
rem ground
ground = GetNextIndex()
make object plain ground, 5000, 5000
color object ground, rgb(20, 120, 20)
xrotate object ground, -90
phy make rigid body static box ground
rem a few boxes
for i = 1 to 20
boxes = GetNextIndex()
make object box boxes, 20, 20, 20
position object boxes, 30 * i, 60, 0
color object boxes, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127))
phy make rigid body dynamic box boxes
`phy set rigid body mass boxes,100.0
next
rem Player controller
make object box player_object, 10, 20, 10
position object player_object,0,100,-100
phy make box character controller player_object, 0, 100, -100, 10, 20, 10, 1, 16, 45
` phy set character controller displacement player_object, 100, 100
` phy set character controller displacement player_object, 1, 1, 1
` phy set character controller displacement player_object, 1
hide object player_object
rem Light inside
light_object = GetNextIndex()
make light light_object
set point light light_object, 0, 600, 0
vec = make vector3( bullet_velocity )
start = 0
dim bullets() as TBullet
empty array bullets()
do
now = timer()
text 10, 20, "FPS: " + STR$(screen fps())
text 10, 40, "Camera: " + STR$(object position x(player_object), 2) + " " + STR$(object position y(player_object), 2) + " " + STR$(object position z(player_object), 2)
text 10, 60, "Bullets: " + str$(array count(bullets()))
array index to top bullets()
while array index valid(bullets())
if now - bullets().start > 10000
phy delete rigid body bullets().id
delete object bullets().id
array delete element bullets()
endif
next array index bullets()
endwhile
position mouse 512, 384
position camera object position x(player_object), object position y(player_object) + 20, object position z(player_object)
rotate camera object angle x(player_object), object angle y(player_object), object angle z(player_object)
remstart
position listener object position x(player_object), object position y(player_object) + 20, object position z(player_object)
rotate listener object angle x(player_object), object angle y(player_object), object angle z(player_object)
remend
oldcamx = camx
oldcamy = camy
camx = wrapvalue( camx + mousemovey() * 0.4 )
camy = wrapvalue( camy + mousemovex() * 0.4 )
xrotate camera 0, curveangle( camx, oldcamx, 24 )
yrotate object player_object, curveangle( camy, oldcamy, 24 )
key = false
if upkey()
key = true
phy move character controller player_object, 200.0
endif
if downkey()
key = true
phy move character controller player_object, -200.0
endif
remstart
if leftkey()
key = 1
turn object left 10, 1.0
endif
if rightkey()
key = 1
turn object right 10, 1.0
endif
remend
if key = false
phy move character controller player_object, 0.0
endif
if mouseclick() = 1
if now - start > 300
x# = object position x(player_object)
y# = object position y(player_object) + 20
z# = object position z(player_object)
bullet = GetBulletIndex()
make object sphere bullet, 10,18,18
color object bullet, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127))
position object bullet, x#, y#, z#
rotate object bullet, camera angle x(), camera angle y(), camera angle z()
move object bullet, 20
x# = object position x(bullet) - x#
y# = object position y(bullet) - y#
z# = object position z(bullet) - z#
set vector3 bullet_velocity, x#, y#, z#
normalize vector3 bullet_velocity, bullet_velocity
x# = x vector3(bullet_velocity)
y# = y vector3(bullet_velocity)
z# = z vector3(bullet_velocity)
phy make rigid body dynamic sphere bullet
`phy set rigid body mass bullet, 100.0
rem phy set rigid body mass bullet_object, 1
phy set rigid body linear velocity bullet, x# * 1000, y# * 1000, z# * 1000
array insert at bottom bullets()
bullets().id = bullet
bullets().start = now
start = now
endif
endif
phy update
sync
loop
end
function GetNextIndex()
inc nObjectIndex
endfunction nObjectIndex
function GetBulletIndex()
inc nBulletIndex
if nBulletIndex > 1100 then nBulletIndex = 1000
endfunction nBulletIndex
Ad Astra Per Asper