Hello,
I'm using Sparky's dll. Can anyone tell me why the collision box for my model is not centered? My model's origin is centered, but if I change the origin to his feet then the collision box fits right. But my model is then standing above the ground. (SEE ATTACTED IMAGE FOR EXAMPLE)
If its helpful, here is my player function:
Function move_player(id, forward, backward, left, right)
checkMoving = forward + backward + left + right
oldx# = object position x(id)
oldy# = object position y(id)
oldz# = object position z(id)
` apply gravity, and user changes to movement
angy# = object angle y(id)
xSpeed#(id) = 0
zSpeed#(id) = 0
` if player is jumping or falling then apply 'normal' gravity
` if not attempt to keep the player stuck to the floor
if xSpeed#(id)=0 and jumptimer=0 then ySpeed#(id) = ySpeed#(id) + 10*gravity# else ySpeed#(id) = ySpeed#(id) + gravity#
if checkMoving <> 0
set object speed 1, 50
`apply forward movement
if forward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,angy#,moveDist#(id)*-1)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,angy#,moveDist#(id)*-1)
if startedJump = 1 then animate(ANI_JUMP) else animate(ANI_WALKING)
endif
`apply backward movement
if backward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,angy#,moveDist#(id))
zSpeed#(id)=zSpeed#(id)+newzvalue(0,angy#,moveDist#(id))
if startedJump = 1 then animate(ANI_JUMP) else animate(ANI_WALKING)
endif
`apply left rotation
if left=1
yrotate object id,wrapvalue(angY#-1.5)
if backward <> 1 and forward <> 1 then animate(ANI_IDLE)
endif
`apply right rotation
if right=1
yrotate object id,wrapvalue(angY#+1.5)
if backward <> 1 and forward <> 1 then animate(ANI_IDLE)
endif
else
if startedJump = 1
set object speed id, 50
animate(ANI_JUMP)
else
set object speed 1, 15
animate(ANI_IDLE)
endif
endif
if controlkey() = 1
if BulletLife=0
Position object 3, object position x(1),object position y(1)+3,object position z(1)
rotate object 3, 0, object angle y (1)-180 ,0
`Set object to object orientation 3,1,1
`yrotate object 3, 180
BulletLife =35
Show object 3
Endif
endif
`work out value with friction
xSpeed#(id)=xSpeed#(id)*friction#(id)
zSpeed#(id)=zSpeed#(id)*friction#(id)
` only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then ySpeed#(id) = ySpeed#(id) + 1.7 : jumptimer = 20 : startedJump = 1
endif
`work out the new position
x#=oldx#+xSpeed#(id)
z#=oldz#+zSpeed#(id)
y#=oldy#+ySpeed#(id)
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+ySpeed#(id),oldz#,radius#,0)
if collide>0
` how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
` FLAT, stick
oldy# = sc_getStaticCollisionY()
else
` STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
text 0, 120, " ON A SLOPE"
endif
if ny#>slope#
` only on ground if standing on flat ground
ground = 1 : startedJump = 0
ySpeed#(id) = 0
else
ground = 0
` if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then ySpeed#(id) = gravity#
endif
else
` nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + ySpeed#(id)
ground = 0
text 0, 120, " IN THE AIR"
endif
if ground = 0 and startedJump = 1 then animate(ANI_JUMP)
` jumptimer will decrease only when player is back on ground
` creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
` handle horizontal movement as sliding
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0) `radius=4.8
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
xSpeed#(id)=0
zSpeed#(id)=0
endif
` POSITION THE PLAYER
position object id,x#,oldy#,z#
If BulletLife > 0
Dec BulletLife
Move object 3,5
If BulletLife = 0 then Hide object 3
Endif
sc_updateObject id
if memblock exist(1) then delete memblock 1
ENDFUNCTION
function animate(frame as integer)
loop object 1, anim(frame).start, anim(frame).stop
endfunction