Hi. I have another problem:
For my non-player models (NPCs) I'm using box collision. Despite that, my player (who uses ellipse collision) can either:
A) Climb over (or almost climb over) the NPCs with low slope (0.9)
or
B) The screen shakes really violently on collision, which dizzifies me. This is when the slope is raised (to 1.0)
Help?
Also, do I need to do this:
`Store the user's old position on the xyz axis
oldx# = object position x(1)
oldy# = object position y(1)
oldz# = object position z(1)
rem apply gravity, and user changes to movement
angy# = object angle y(1)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not then attempt to keep the player stuck to the floor
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
rem Move player (eight-directional movement)
If Downkey()=1 AND Leftkey()=1
yrotate object 1,45
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Downkey()=1 AND Rightkey()=1
yrotate object 1,-45
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Upkey()=1 AND Leftkey()=1
yrotate object 1,135
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Upkey()=1 AND Rightkey()=1
yrotate object 1,225
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Upkey()=1
yrotate object 1,180
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Downkey()=1
yrotate object 1,360
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Leftkey()=1
yrotate object 1,90
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
else
If Rightkey()=1
yrotate object 1,270
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
walk=1
endif : endif : endif: endif : endif : endif : endif : endif
rem END directional movement----------------------------------------------------
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#
y# = oldy#+vy#
z# = oldz#+vz#
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.
`for i = 1 to 2
collide1 = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,y#,oldz#,radius#,0)
collide2 = sc_SphereCastGroup(1,oldx#,oldy# + radius#,oldz#,oldx#,y# + radius#,oldz#,radius#,0)
if collide1 OR collide2>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
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
collide1 = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
collide2 = sc_SphereSlideGroup(1,oldx#,oldy#+radius#,oldz#,x#,oldy#+radius#,z#,radius#,0)
if collide1 OR collide2>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 1,x#,oldy#,z#
sc_updateObject 1
for EVERY model I want to collide? Right now my enemies aren't colliding and since they're controlled by AI, their movement coding is going to be longer than even that.
Please respond soon, thanks.
a total noob.
Currently working on - Enemy AI and Battle Algorithms