Hello again all.
I have been stuck for 2 days on this now, so I turn to you guys for help. I am using Dark Physics for a character control system, which for the most part works just fine. But I can´t for the life of me get the character to jump properly. I can get him to jump, but whenever I move forward, he´s stuck to the ground, which I don´t understand.
The jumping-code
is executed when jumping and moving forward, but for some reason, he doesn´t move up.
I´ve included a simplified version of the code (no media fx, so bear with me).
Controls are arrowkeys/asdw and spacekey to jump.
I would much appreciate it if someone could take a look at it.
It´s built partly with the perfect 60 fps example but I doubt that has anything to do with it - just saying so you don´t think I´m trying to take credit for that piece of code, which I´m not.
set display mode 800,600,32,1
ink rgb(100,170,220),0
box 0,0,255,255
ink rgb(60,90,120),0
box 0,0,127,127
box 128,128,255,255
get image 1,0,0,255,255
sync on : sync rate 0
now as DWORD
goal as DWORD
starttime as DWORD
intstep as DWORD
intstepmode as integer
timer_ticks as integer
timer_ticks_count as integer
timer_ticks_myxpos# as float
t$=get time$() : while get time$()=t$ : endwhile
starttime=timer()
now=starttime : intstep=16 : fpsrate=60
autocam off
phy start
set camera range 0.5, 30000
hide mouse
charspeed# = 100
playerturn# = 2
camdist# = 75
camheight# = 50
debug#=0
player_object = 3
waterobject1#=111
waterobject2#=112
gravityvalue#=-10
blendtest# = 1
cheapwater#=1
jumping# = 0
make object box 1,40000,200,40000
position object 1,0,-400,0
phy make rigid body static mesh 1
texture object 1,1
scale object texture 1,50,50
make object box 3, 5, 11, 3.5
position object 3,0,0,0
phy make box character controller 3, 0, 0, 0, 5, 11, 3.5, 1, 10.5, 45.0
if debug#=1 then ghost object on 3 else hide object 3
make object cube 4,1
hide object 4
make object box 5,10,22,7
yrotate object 5,180
fix object pivot 5
do
goal=timer()
while now+intstep<=goal
`
now=now+intstep
`
inc intstepmode : if intstepmode>2 then intstepmode=0
if intstepmode=0 then intstep=16
if intstepmode=1 then intstep=17
if intstepmode=2 then intstep=17
`
inc timer_ticks
if timer_ticks = 60
`
inc timer_ticks_count
timer_ticks = 0
`
endif
position object 5,object position x(3),object position y(3)-11,object position z(3)
rotate object 5,object angle x(3),object angle y(3),object angle z(3)
position object 4,object position x(3),object position y(3),object position z(3)
rotate object 4,object angle x(3),object angle y(3),object angle z(3)
move object 4,0-camdist#
xrotate object 4, curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
position camera object position x(4),object position y(4)+camheight#,object position z(4)
rotate camera object angle x(4)+20,object angle y(4),object angle z(4)
key = 0
walk = 0
if keystate (17) OR upkey()
key = 1
walk = 1
phy move character controller player_object, charspeed#
endif
if keystate (31) OR downkey()
key = 1
walk = 1
phy move character controller player_object, 0-charspeed#
endif
if keystate(30) OR leftkey()
key=1
yrotate object 3,object angle y(3)-playerturn#
endif
if keystate(32) OR rightkey()
key=1
yrotate object 3,object angle y(3)+playerturn#
endif
strafe_Y = object angle y(player_object)
if keystate(16)
key = 1
strafe_Y = wrapvalue( strafe_Y - 90 )
yrotate object player_object, strafe_Y
phy move character controller player_object, charspeed#
strafe_Y = wrapvalue( strafe_Y + 90 )
yrotate object player_object, strafe_Y
endif
if keystate(18)
key = 1
strafe_Y = wrapvalue( strafe_Y - 90 )
yrotate object player_object, strafe_Y
phy move character controller player_object, 0-charspeed#
strafe_Y = wrapvalue( strafe_Y + 90 )
yrotate object player_object, strafe_Y
endif
if spacekey()=1 and jumping#=0 and gravityvalue#=-10 then gravityvalue#=145 : jumping#=1 : key = 1
if gravityvalue#>144 and jumping#=1 then inc gravityvalue#,2
if gravityvalue#>170 then dec gravityvalue#,2 : jumping#=0
if gravityvalue#>99 and jumping#=0 then dec gravityvalue#,2
if gravityvalue#<100 and jumping#=0 then gravityvalue#=-10
rotx = wrapvalue(rotx - 90)
xrotate object player_object,rotx
phy move character controller player_object, gravityvalue#
rotx = wrapvalue(rotx + 90)
xrotate object player_object,rotx
if key = 0 AND gravityvalue#=-10
phy move character controller 3, 0.0
endif
phy update
inc timer_ticks_myxpos#,1.0 : if timer_ticks_myxpos# > screen width() then timer_ticks_myxpos#=0.0
endwhile
sync
loop
it also seems that the "gravity" force is applied much more forcefully when moving forward, which could explain why the jumping doesn´t take place - the added "gravity" simply kills the upwards force of the jump. However this gravity seems built into DP, and I can´t for the life of me get rid of it (which is very annoying).
Thanks in advance!