Ok, since noone is answering, I guess I am asking something wrong here... I have tried many things, if you would like to help, here is the Entire code
sync on
sync rate 60
autocam off
Hide Mouse
randomize timer()
global radius# as double float : radius# = 2.0
global movement as integer
Global Move as integer
MakeLevel()
MakePlayer()
global rtimer as integer
global stimer as integer
global vtimer as integer
rem player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global gravity# as double float : gravity# = -0.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
global jumptimer as integer : jumptimer = 0
global view as integer : view = 1
Set Text Font "Matura MT Script Capitals"
Set Text Size 21
color Ambient Light rgb (100,100,250)
Color Backdrop rgb (000,000,50)
do
MovePlayer()
AI()
Attack()
Menu()
rem change view
if shiftkey()=1 and vtimer<timer() then vtimer = timer()+300 : view = 1-view
endif
positionCameraToObject(2,view)
text 0,30,"FPS: "+str$(screen fps())
sync
loop
function makeLevel()
REM All Group 1 Objects World
load object "World/Joined/Ground01.x",10
sc_setupComplexObject 10,1,2
load object "World/Joined/Dojo_Ground01.x",11
sc_setupComplexObject 11,1,2
load object "World/Joined/Dojo_Ground01b.x",12
sc_setupComplexObject 12,1,2
`sc_setupObject 1,1,0
REM All Group 2 Objects Enemies
REM ALL Group 3 Objects Interacts
REM ALL Group 4 Objects Weapons
endfunction
function makePlayer()
Load object "Characters/Main_Characters/Hero_No_Scarf_04.x",2
Fix object pivot 2
SC_SetupObject 2,0,1
Load Object "Characters/Main_Characters/HeroScarf01.x",5
Fix Object Pivot 5
SC_SetupObject 5,0,1
Position Object 2,0,100,0
endfunction
function movePlayer()
if movement=0 then movement=1
if keystate(2)=1 then movement=1
if keystate(3)=1 then movement=2
if keystate(4)=1 then movement=3
if movement=1 then movement_standing(2)
if movement=2 then movement_crouching(2)
if movement=3 then movement_prone(2)
endfunction
function movement_standing(obj)
rem rotate player with mouse
Set Object Frame 2,0
Loop Object 2,0,17
If Move = 0 then loop object 2,0,5 : Loop Object 5,0,5
yrotate object 2,object angle y(2)+mousemovex()/3.0 : Move# = 1
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
Move = Move#
rem apply gravity, and user changes to movement
angy# = object angle y(2)
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
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#)/3 : vz# = vz# - sin(angy#)/3 : Move# = 1
if keystate(30)=1 then vx# = vx# - cos(angy#)/3 : vz# = vz# + sin(angy#)/3 : Move# = 1
if keystate(31)=1 then vx# = vx# - sin(angy#)/3 : vz# = vz# - cos(angy#)/3 : Move# = 1
if keystate(17)=1 then vx# = vx# + sin(angy#)/3 : vz# = vz# + cos(angy#)/3 : Move# = 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#
y# = oldy#+vy#
z# = oldz#+vz#
if Move = 1 then loop object 2,6,17 : Loop Object 5,6,17
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
endif
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_SphereCastGroup(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 To walk up stairs
dy# = oldy#-sc_getStaticCollisionY()
if dy#<slope# and dy#>0 and ground=1 then vy# = 0.1
endif
position object 2,x#,oldy#,z#
sc_updateObject 2
endfunction
Function Movement_Crouching(obj)
rem rotate player with mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem apply gravity, and user changes to movement
angy# = object angle y(2)
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
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#)/6 : vz# = vz# - sin(angy#)/6 : Move = 2
if keystate(30)=1 then vx# = vx# - cos(angy#)/6 : vz# = vz# + sin(angy#)/6 : Move = 2
if keystate(31)=1 then vx# = vx# - sin(angy#)/6 : vz# = vz# - cos(angy#)/6 : Move = 2
if keystate(17)=1 then vx# = vx# + sin(angy#)/6 : vz# = vz# + cos(angy#)/6 : Move = 2
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#
If Move = 2 then Frame#=14
Set object Frame 2,14
inc Frame#
If Move = 2 and Frame#=14 then set object frame 2,15 : Inc Frame#
If Move = 2 and Frame#=15 then set object frame 2,16 : Inc Frame#
If Move = 2 and Frame#=16 then set object frame 2,17 : Inc Frame#
If Move = 2 and Frame#=17 then set object frame 2,18 : Inc Frame#
If Move = 2 and Frame#=18 then set object frame 2,19 : Inc Frame#
if Frame#>19 then Frame#=14
If Move = 0 then stop object (2)
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,littleRadius#,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
endif
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 To walk up stairs
dy# = oldy#-sc_getStaticCollisionY()
if dy#<slope# and dy#>0 and ground=1 then vy# = 0.7
endif
rem position the player
position object 2,x#,oldy#,z#
sc_updateObject 2
endfunction
Function Movement_Prone(obj)
rem rotate player with mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem apply gravity, and user changes to movement
angy# = object angle y(2)
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
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#)/8 : vz# = vz# - sin(angy#)/8
if keystate(30)=1 then vx# = vx# - cos(angy#)/8 : vz# = vz# + sin(angy#)/8
if keystate(31)=1 then vx# = vx# - sin(angy#)/8 : vz# = vz# - cos(angy#)/8
if keystate(17)=1 then vx# = vx# + sin(angy#)/8 : vz# = vz# + cos(angy#)/8
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.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,littleRadius#,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
endif
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 To walk up stairs
dy# = oldy#-sc_getStaticCollisionY()
if dy#<slope# and dy#>0 and ground=1 then vy# = 0.7
endif
rem position the player
position object 2,x#,oldy#,z#
sc_updateObject 2
endfunction
function positionCameraToObject(obj,thirdPerson)
position camera object position x(2),object position y(2),object position z(2)
position object 5, object position x(2),object position y(2), object position z(2)
rotate object 5, object angle x(2),object angle y(2),object angle z(2)
rotate camera object angle x(2),object angle y(2),object angle z(2)
if thirdPerson=1
pitch camera down 17
move camera -20
else
thirdPerson=0
position camera object position x(2),object position y(2)+10,object position z(2)
rotate camera object angle x(2),object angle y(2),object angle z(2)
REM won't rotate up/down without using rotate object with mousemovey
xrotate camera 0,camera angle x(0)+mousemovey()/3.0
yrotate camera 0,camera angle y(0)+mousemovex()/3.0
endif
endfunction
Function AI()
endfunction
Function Attack()
endfunction
Function Menu()
endfunction
REM END OF ALL
if memblock exist(1) then delete memblock 1
For the most part its' just sparkys code, minus a few things... you can just disregard the Crouching and Prone functions for the standing won't even work, little alone the others, except the speed.
As well, here is my model, just the ninja, not the scarf, so you can also remove the scarf when testing...
Another problem I have had is that because of the spherecasting, and collision it gives the appearance that the ninja is floating above the ground... Any ideas, i reduced the radius as small as possible to allow for stair climbing, and so that you don't fall through the ground.
I've also tried repositioning the model in my modeling program, but there was no result, because it's set to sphere... raycasting worked for collision straight down, but it kinda sucked when it came to the rest, it would not detect too much.
I could just make a new object for each frame, but that's just a horrible thing.... but, i may need to... since it only loops like 1 or 2 frames as compared to 12 or so.
www.soundclick.com/octoberscry ---> My Doom Metal Band