Hey everybody,
I know this should not be that hard, but for some reason I cannot get it to work. I wish to have a different Y radius than the X,Z radius.
I tried many things in the code, even tried to combine two collision boxes for one character but I\'m lost. When playing around with the radius, weird things happen and adding a second object, with collision that moves, it not so hard, but I\'m clueless on how to add the second object to the collision code.
Here is my current code (based on the demo):
// Get Old Position Data
oldx# = object position x(player_col)
oldy# = object position y(player_col)
oldz# = object position z(player_col)
// apply gravity, and user changes to movement
angy# = object angle y(player_col)
pl_vx# = 0
pl_vz# = 0
// if player is jumping or falling then apply \'normal\' gravity
// if not attempt to keep the player stuck to the floor
if pl_vy# = 0 and pl_jumptimer = 0 then pl_vy# = pl_vy# + 10*pl_gravity# else pl_vy# = pl_vy# + pl_gravity#
if keystate(32)=1 : pl_vx# = pl_vx# + cos(angy#) * pl_speed# : pl_vz# = pl_vz# - sin(angy#) * pl_speed# : endif
if keystate(30)=1 : pl_vx# = pl_vx# - cos(angy#) * pl_speed# : pl_vz# = pl_vz# + sin(angy#) * pl_speed# : endif
if keystate(31)=1 : pl_vx# = pl_vx# - sin(angy#) * pl_speed# : pl_vz# = pl_vz# - cos(angy#) * pl_speed# : endif
if keystate(17)=1 : pl_vx# = pl_vx# + sin(angy#) * pl_speed# : pl_vz# = pl_vz# + cos(angy#) * pl_speed# : endif
// only jump if on ground, and a certain time after last jump
if pl_ground = 1
// Original jump code
if spacekey()=1 and pl_jumptimer = 0 then pl_vy# = pl_vy# + pl_jumpheight# : pl_jumptimer = 20
endif
// this would be the player\'s final position without collision
x# = oldx# + pl_vx#
y# = oldy# + pl_vy#
z# = oldz# + pl_vz#
// first handle gravity - seperated from horizontal movement
// to achieve a more realistic effect
// Method: simple - cast a sphere vertically down, if it hits the level then
// position the object there (sticky collision) then move
// on to horizontal movement
// more complex - if we were to only use the simple method the player would be
// allowed to climb almost vertical slopes. Alternative is to
// get the normalY direction to work out how flat the gorund
// below the player is, 0-slope# is flatter, slope#-1 is steeper.
// if it\'s flat, use sticky collision, if it\'s steep slide the
// player down the slope. Changing slope# determines how steep the
// player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1, oldx#, oldy#, oldz#, oldx#, oldy# + pl_vy#, oldz#, pl_radius#, 0)
if collide > 0
// how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#) > pl_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#
endif
// ny# < 0 means the player has hit a ceiling rather than a floor
if ny# > pl_slope#
// only on ground if standing on flat ground
pl_ground = 1
pl_vy# = 0
else
pl_ground = 0
// if player has hit a flat ceiling then stop vy# movement
if ny# < -pl_slope# then pl_vy# = pl_gravity#
endif
else
// nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + pl_vy#
pl_ground = 0
endif
// jumptimer will decrease only when player is back on ground
// creates a pause between two successive jumps
if pl_ground = 1 and pl_jumptimer>0 then dec pl_jumptimer
// handle horizontal movement as sliding
// player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1, oldx#, oldy#, oldz#, x#, oldy#, z#, pl_radius#, 0)
if collide > 0
// if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
pl_vx# = 0
pl_vz# = 0
// possible code for giving the player a jumping help up stairs...
// might be useful if slope# is set very high but stairs are still required
dy# = oldy# - sc_getStaticCollisionY()
if dy# < pl_slope# and dy# > 0 and pl_ground = 1 then pl_vy# = 0.7
endif
Anyone can help me with a different Y radius or how to add a second collision object?
Thanks in advanced.
Regards Sph!nx