I am having problems with my code for a school project. I can jump and turn, but I am unable to move back and forth since I put in the code to jump. Can anyone help me? I've shorten my code to the sections where I believe my problem is.
MainSection:
`DECLARE VARIABLES
Rem Gavity
Gravity#=.5:rem How powerful gravity is
MyPower=10:rem How strong the player can jump
MySpeed=9:rem How fast the player can run
MyScore=0:rem Starting score is 0
MyAcceleration#=0.0:rem Start without jumping or falling
`OBJECT ORIENTATIONS (Pre-Movement, Pre-Collision)
`Player Character
P1X# = object position X(1)
P1Y# = object position Y(1)
P1Z# = object position Z(1)
A1X = object angle X(1)
A1Y = object angle Y(1)
A1Z = object angle Z(1)
`CONTROL INPUT
if Spacekey()=1 and MyAcceleration# = 0.0 : rem Make sure I've fully landed before I can jump again
P1Y# = P1Y# - Gravity# : rem Look below me
position object 1, P1X#,P1Y#,P1Z# : rem Feel below me
for t = 6 to NumberOfSteps+6
if object collision(1,t)>0 : rem If feel a solid object below me
MyAcceleration# = MyPower : rem Prepare to jump!
endif
next t
P1Y# = P1Y# + Gravity# : rem Look up
position object 1, P1X#,P1Y#,P1Z# : rem Move back
endif
`Acceleration and Pitch
if upkey()=1 then move object 1,10
if Downkey()=1 then move object 1,-10
`Turning and Banking
if Leftkey()=1 then Yrotate object 1,wrapvalue(A1Y-5)
if Rightkey()=1 then Yrotate object 1,wrapvalue(A1Y+5)
`CHECK COLLISIONS
Rem Gravity Effects
if MyAcceleration# = 0.0 : rem If I'm not moving up or down
EmptySpace = 0 : ObjectsChecked = 0 : rem Get ready to start checking collisions
for CheckObject = 6 to NumberOfSteps+6 : rem Check the floor and every step object
if object collision(1,CheckObject)>0 : rem If I'm touching something
P1Y# = P1Y# - Gravity# : rem Look below me
position object 1, P1X#,P1Y#,P1Z# : rem Feel below me
if object collision(1,CheckObject) = 0 : rem If I feel only air
EmptySpace = EmptySpace + 1 : rem Mark up a free space
endif : rem I'm touching something, but it's not below me
P1Y# = P1Y# + Gravity# : rem Look up
position object 1, P1X#,P1Y#,P1Z# : rem Move back
else : rem If I'm not touching anything
EmptySpace = EmptySpace + 1 : rem rem Mark up a free space
endif
ObjectsChecked = ObjectsChecked + 1 : rem Done with that one!
next CheckObject : rem On to the next one!
if EmptySpace = ObjectsChecked : rem If I've checked all the objects and nothing is below me
MyAcceleration# = MyAcceleration# - Gravity# : rem Gravity begins to pull
endif
endif
if MyAcceleration# <> 0.0 : rem If I'm moving
P1Y# = P1Y# + MyAcceleration# : rem Find where I'm going
position object 1, P1X#,P1Y#,P1Z# : rem Put me there
EmptySpace = 0 : ObjectsChecked = 0 : rem Get ready to start checking collisions
for CheckObject = 6 to NumberOfSteps+6 : rem Check the floor and every step object
if object collision(1,CheckObject)>0 : rem If I hit an object
P1Y# = P1Y# - MyAcceleration# : rem Find where I was
position object 1, P1X#,P1Y#,P1Z# : rem Put me back
MyAcceleration# = 0.0 : rem Stop me from moving
else : rem If the space I'm going to is just air
EmptySpace = EmptySpace + 1 : rem rem Mark up a free space
endif
ObjectsChecked = ObjectsChecked + 1 : rem Done with that one!
next CheckObject : rem On to the next one!
if EmptySpace = ObjectsChecked : rem If I've checked all the objects and nothing is in my path
MyAcceleration# = MyAcceleration# - Gravity# : rem Gravity pulls more
endif
endif
`Player Character
If object collision (1,0)>0 then position object 1,P1X#,P1Y#,P1Z#