Hello,
i got some problems with sparkys collision.
I can't get a "clean" collision.
Well, side collision is working "okay". (Not good - but okay)
My problem is i want the objects on the floor. But i can't get it to work. It's driving me crazy, seriously.
Normaly i wouldn't ask for such a favor, but could someone fix my code and add that y stuff?
A special thanks for that person somewhere in the game would be sure...
Well here's a small video to show my problems: (Watch in 1080p to see everything clear)
http://youtu.be/OL1zTVbnp8Q?hd=1
my code to setup the enemy:
sc_setupObject Enemy_ObjectID,1,2
Enemy(t).Height# = EnemyType(enemytype).Height#
Enemy(t).Radius# = EnemyType(enemytype).Radius#
enemy move code:
Enemy_ObjectID = Enemy(i).ObjID#
if object exist(Enemy_ObjectID) = 1
oldx# = object position x(Enemy_ObjectID)
oldy# = object position y(Enemy_ObjectID)
oldz# = object position z(Enemy_ObjectID)
point object Enemy_ObjectID,object position x(Player_ObjectID),Enemy(i).Height#,object position z(Player_ObjectID)
//text object screen x(Enemy_ObjectID),object screen y(Enemy_ObjectID),str$(Enemy(i).Height#)
move object Enemy_ObjectID,0.5 * Enemy(i).MoveSpeed#
rotate object Enemy_ObjectID, 0, object angle y( Enemy_ObjectID )-180, object angle z( Enemy_ObjectID ) //object angle z( Enemy_ObjectID ) object angle x( Enemy_ObjectID )
x# = object position x(Enemy_ObjectID)
y# = object position y(Enemy_ObjectID)
z# = object position z(Enemy_ObjectID)
rem little spheres collide with all (0)
collide = sc_sphereSlideGroup(0,oldx#,oldy#,oldz#,x#,y#,z#,Enemy(i).Radius#,Enemy_ObjectID)
if collide>0
position object Enemy_ObjectID,sc_getCollisionSlideX(),oldy#,sc_getCollisionSlideZ()
endif
sc_updateObject Enemy_ObjectID
endif
Enemy(i).Height# is the Height you see at the debug info, same for Radius.
my code to setup the player:
sc_setupObject Player_ObjectID,1,2
my code to move the player:
function movePlayer()
rem rotate player with mouse
yrotate object Player_ObjectID,object angle y(Player_ObjectID)+mousemovex()/3.0
//xrotate object 2,object angle x(2)+mousemovey()/3.0
oldx# = object position x(Player_ObjectID)
oldy# = object position y(Player_ObjectID)
oldz# = object position z(Player_ObjectID)
rem apply gravity, and user changes to movement
angy# = object angle y(Player_ObjectID)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
Player_animation = 0
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#) : player_animation = 1
if keystate(30)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#) : player_animation = 1
if keystate(31)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#) : player_animation = 1
if keystate(17)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#) : player_animation = 1
rem only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx# * (Player_walkspeed)
y# = oldy#+vy# * (Player_walkspeed)
z# = oldz#+vz# * (Player_walkspeed)
rem first handle gravity - seperated from horizontal movement
rem to achieve a more realistic effect
rem Method: simple - cast a sphere vertically down, if it hits the level then
rem position the object there (sticky collision) then move
rem on to horizontal movement
rem more complex - if we were to only use the simple method the player would be
rem allowed to climb almost vertical slopes. Alternative is to
rem get the normalY direction to work out how flat the gorund
rem below the player is, 0-slope# is flatter, slope#-1 is steeper.
rem if it's flat, use sticky collision, if it's steep slide the
rem player down the slope. Changing slope# determines how steep the
rem player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
player_animation = 2
endif
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object Player_ObjectID,x#,oldy#,z#
sc_updateObject Player_ObjectID
//position object Player_ObjectID,x#,oldy#-15,z#
//Flashlight
//rotate light 1,object angle x(Player_ObjectID),object angle y(Player_ObjectID)-180,object angle z(Player_ObjectID)
//rotate light 2,object angle x(Player_ObjectID),object angle y(Player_ObjectID)-180,object angle z(Player_ObjectID)
//position light 1,x#,oldy#+60,z#
//poition light 2,x# ,oldy#+60,z#
endfunction
It's mostly taken from the sliding demo.
Hope somebody can help me

Best regards.
e/ Player Jump is not needed, doesn't work anyway :x