ID:156799
 
Alright so I have just finished adding jumping onto my project and I remember making a shadow that stays in one spot under you're player and doesn't move last year. I just recently got back to programming so im trying to get the hang of everything again. This is what I have so far:

        Jump()
var/D=20//How high you will appear to jump
var/D2=1//How long you will appear to jump
var/D3=1//How high you will become in the air
var/D4=6//How long you will be airborne
//var/D3=10//H
if(src.Jumping==0)
src.Jumping=1
src.icon_state="Jump"
if(src.CS>=2)
D=20
D2=4
D3=3
D4=20
src.Height=D3
spawn(D4)
src.Height=0
src.pixel_y+=D
sleep(D2)
src.pixel_y+=D
sleep(D2)
src.underlays+=new/obj/Shadow
src.pixel_y+=D
spawn(D2)
src.pixel_y+=D
sleep(D2)
src.pixel_y+=D
sleep(D2)
src.pixel_y-=D
sleep(D2)
src.pixel_y-=D
sleep(D2)
src.pixel_y-=D
sleep(D2)
src.pixel_y-=D
sleep(D2)
src.pixel_y-=D
src.underlays-=/obj/Shadow
src.pixel_y=0
src.Jumping=0
src.icon_state=""
else
usr<<"You are already jumping"
return


The problem is that the shadow moves down as the player is landing. Is there a way that I can make it so the shadow stays locked under the player so the player has a nice idea where he's going to land?
Im not sure exactly what the height variable is doing but the first thing that would come to my head would be to add a new variable and a lot of checks inbetween.

below:
        Jump()
var/D=20//How high you will appear to jump
var/D2=1//How long you will appear to jump
var/mob/S = new/obj/shadow
var/D3=1//How high you will become in the air
var/D4=6//How long you will be airborne
//var/D3=10//H
if(src.Jumping==0)
src.Jumping=1
src.icon_state="Jump"
if(src.CS>=2)
D=20
D2=4
D3=3
D4=20
src.Height=D3
spawn(D4)
src.Height=0
src.pixel_y+=D
sleep(D2)
src.pixel_y+=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y+=D
spawn(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y+=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y+=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y-=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y-=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y-=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y-=D
sleep(D2)
S.loc = locate(src.x,src.y,src.z)
src.pixel_y-=D
src.pixel_y=0
del(S)
src.Jumping=0
src.icon_state=""
else
usr<<"You are already jumping"
return


You might be able to reduce the number of checks with the same result you will just have to test it and see what happens ;)
In response to Tonyth
Thank you ( : it works perfectly fine. I tried removing some checks but it didn't come out as well.