Posted: 25th Jun 2007 20:15
i am trying to make a player movement code and i'm not getting anywhere whatsoever

if am trying to make it smooth (i can easily do it but looks jagged)

this code just doesn't work
+ Code Snippet
if upkey()=1
player_oldz#=object position z(1)
position object 1,0,0,100
player_newz#=Curvevalue(object position z(1),old_pz#,4)
position object 1,0,0,player_oldz#
endif



also another question is when i press left, i want the player char to rotate 90 degrees, but i want it to look a bit smoother as it just sort of appears in the other direction, is that possable
Posted: 25th Jun 2007 20:29
+ Code Snippet
player_newz#=Curvevalue(object position z(1),old_pz#,4)
position object 1,0,0,player_****oldz#****

And there lies your problem.
Posted: 25th Jun 2007 20:34
Should really just be:

playerz# = curvevalue(object position z(1), playerz#, 4)
Posted: 25th Jun 2007 20:37
oh yeh

but now i've got another problem, the object moves, but stops about 74 units away

it starts moving really fast, then slows to a stop, but when i let go of the key before it stops it stops suddenly
Posted: 25th Jun 2007 20:49
its not going anywhere

i've even turned the speed up2 9999999999999999999999999999999999999999999999999999999999999999
to see if it was just moving really slowly, but its not

this is the code
+ Code Snippet
if upkey()=1
player_oldz#=Curvevalue(object position z(1),player_oldz#,3)
player_newz# = curvevalue(object position z(1), player_newz#, 3)
endif
position object 1,0,0,player_newz#




a good lesson has come from this tho i can use

+ Code Snippet
player_oldz#=Curvevalue(object position z(1),player_oldz#,98)
position object 1,34,234,21
player_newz# = curvevalue(object position z(1), player_newz#, 98)


and it will slowly move my player to that position and stop smoothly

i can use that code in my cut-scene script file for the opening story
Posted: 25th Jun 2007 20:52
A higher value equals more lag. You're not actually incrementing or decrementing player_newz#, by the way.
Posted: 25th Jun 2007 20:53
i did try

+ Code Snippet
player_newz#=player_newz#+1


but it only moves the player 1 unit
Posted: 25th Jun 2007 20:55
Well, make the upkey do that, and then use this:
+ Code Snippet
position object 1,0,0,curvevalue(player_newz#,object position z(1),25)
Posted: 25th Jun 2007 20:58
aha that works very well, cheerz Ferret
didn't think it'd be that easy

the other problem is rotation, i can do normal rotation easily, but i want (classic char movement)

so basicly when i press the left key, the player will rotate 90 degrees and run left, rather than just rotate left.
Posted: 25th Jun 2007 21:01
+ Code Snippet
if upkey()||downkey()||leftkey()||rightkey() then yrotate object 1,curveangle(atanfull(rightkey()-leftkey(),upkey()-downkey()),object angle y(1),25)

Untested.
Posted: 25th Jun 2007 21:23
yay it works! thanx
but is there anyway this movement code can be improved
it looks good but somethings not quite right & i can't quite put my finger on it

i know the codes messy, theres alot of un-used labels/functions & variables, they will be used & changed later on

no media needed, just copy & paste

+ Code Snippet
// aftermath engine player_start and player_control function

sync on : sync rate 63.6
autocam off

position camera 0,128,-64
xrotate camera 30

move_forward=17
move_back=31
move_left=30
move_right=32

player_start(1,0,0,0,0)
`player_control()

do






if keystate(move_forward)||keystate(move_back)||keystate(move_left)||keystate(move_right) then yrotate object 1,curveangle(atanfull(keystate(move_right)-keystate(move_left),keystate(move_forward)-keystate(move_back)),object angle y(1),10.3)


if keystate(move_forward)
player_newz#=player_newz#+1.1
endif
if keystate(move_back)
player_newz#=player_newz#-1.1
endif

if keystate(move_left)
player_newx#=player_newx#-1.1
endif

if keystate(move_right)
player_newx#=player_newx#+1.1
endif

position object 1,curvevalue(player_newx#,object position x(1),3),0,curvevalue(player_newz#,object position z(1),4.3)

sync
loop

cfg_gravity=20

move_forward=17
move_back=31
move_left=30
move_right=32


function player_start(player_num,player_yrot,player_x,player_y,player_z)
    make object box player_num,24,52,24
    position object player_num,player_x,player_y,player_z
    yrotate object player_num,player_yrot
endfunction



function player_control
`smooth movement
player_newx#=0
player_newz#=0
player_oldx#=0
player_oldz#=0
`smooth rotation
player_newroty#=0
player_oldroty#=0
endfunction


player_control:

return