Just trying to make a small jump timer so that the character cannot jump round like a lunatic and requires at least 1 second or so rest before the spacebar will have an effect on the characters jumping.
This is the unrunable jump code.
This is all inside a movement function that positions the camera at the objects position, and has the standard WASD movement and mouselook, this all works fine.
If Spacekey() = 1 AND Jumping = 0 AND Jump_Timer = 0
Jump = 1
EndIf
` Remstart
If Jump = 1
Ground = PlayerY
Jump_Speed = 2.8
Jumping = 1
Jump = 0
EndIf
` Remend
`Remstart
If Jumping = 1
Dec Jump_Speed, 0.2
Position Object 1, PlayerX, PlayerY + Jump_Speed, PlayerZ
`Remstart
If PlayerY <= Ground
Jumping = 0
Jump_Speed = 0
Ground = 0
PlayerY = Ground
Jump_Timer = 1
EndIf
`Remend
EndIf
`Remend
If Jump_Timer <= 0
Jump_Timer = 0
EndIf
`remstart
If Jump_Timer >= 0 ` Should work when its more than 0
Dec Jump_Timer, 0.05
EndIf
`remend
Endfunction
And my global variables to do with all this are as follows
Global Jump As Integer
Global Jump_Speed As Float
Global Ground As Integer
Global Jumping As Integer
Global PlayerX As Float
Global PlayerY As Float
Global PlayerZ As Float
Global Jump_Timer As Float
I think i am putting something as a float that i shouldnt be, or something as an integer that shouldnt be, but i have tried everything swapped around and come up with nothing.
It seems to do 2 things that annoy the living p*ss out of me.
1) Does not like Dec for decreasing values properly even though i know this works as i have used it hundreds of times for floats and integers.
2) Shockingly poor inaccurate float values. I have a few bits of text telling me what some of the values are and for example i have the jump_timer set to 1. It does not go to 1 but instead chooses a value just a little under 1, this of course knocks a few things out of wack and is why i have lots of things in that code that say if a value is not 0 then make it 0 even though it probably should be.
So after taking a step back and then re-writing it, then taking a nother step back i cant figure out a good method to make a char jump, then not be able to jump for a split second or so before jumping again i think i will throw this out there and see what suggestions i get as i dont mind re-writing it out and getting a better knowledge of what is happening when the variables are being changed. As things are happening so fast its difficult to catch them.
Thanks in advance.
For anyone who is interested i am doing my own sort of version of learning from one of Ruccas's fps tutorials and my full code so far can be found here.
Sync On
Sync Rate 60
Hide Mouse
`Set Window Off
Maximize Window
`Set Window Size 1280, 800
`Set Window Position 180, 180
Rem Variable Setup
Global EnemyHP As Integer = 5000
Global Ammo As Integer = 1000
Global MaxAmmo As Integer = 1000
Global Clips As Integer = 3
Global MaxClips As Integer = 3
Global Time As Float
Global Seconds As Integer
Global ReloadTime As Float
Global Reload As Integer
Global CamY, CamX As Integer
Global Jump As Integer
Global Jump_Speed As Float
Global Ground As Integer
Global Jumping As Integer
Global PlayerX As Float
Global PlayerY As Float
Global PlayerZ As Float
Global Jump_Timer As Float
Make Object Sphere 1, 50 ` Player Object
Color Object 1, RGB(000,255,000)
Make Object Sphere 2, 50 ` Enemy Object
Color Object 2, RGB(255,000,000)
Position Object 2, 130, 0, 0
Make Object Box 3, 100, 100, 5 ` Wall
Position Object 3, 0, 0, 150
Make Object Box 4, 15, 20, 50 ` Ammo Clip
Color Object 4, RGB(000,255,255)
Position Object 4, -40, 0, 0
Make Object Triangle 9999, 0,0,0,0,0,0,0,0,0 ` Limb Setup
Make Mesh From Object 1, 9999
Delete Object 9999
Add Limb 1, 1, 1
Offset Limb 1, 1, 0, 0, 500
Delete Mesh 1
Hide Limb 1,1
Time = Timer()
Do
FPS# = Screen FPS()
Text 0,0, "FPS: " + str$(FPS#)
Timers()
Movement()
Shooting()
Ammo_Clip()
`If SpaceKey() = 1 Then Space = 1
Text 0,20, "Ammo: " + Str$(Ammo)
Text 0,40, "Clips: " + Str$(Clips)
Text 0,60, "Jump: " + Str$(Jump)
Text 0,80, "Jumping: " + str$(Jumping)
Text 0,100, "Jump_Speed: " + str$(Jump_Speed)
Text 0,120, "Jump_Timer: " + str$(Jump_Timer)
Text 0,140, "Ground: " + str$(Ground)
Circle Screen Width()/2, Screen Height()/2, 5
`Space = 0
Sync
Loop
Function Timers()
If Timer() = Time + 1000
Inc Seconds
Time = Timer()
EndIf
EndFunction
Function Movement()
PlayerX = Object Position X (1)
PlayerY = Object Position Y (1)
PlayerZ = Object Position Z (1)
`Position Object 1, PlayerX, PlayerY, PlayerZ
Position Camera PlayerX, PlayerY, PlayerZ
`WASD
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,2
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-2
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,2.2
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,2.2
`Mouse Look
CamY = CamY + MouseMoveX() * 0.2
CamX = CamX + MouseMoveY() * 0.2
YRotate Camera CamY
XRotate Camera CamX
YRotate Object 1, CamY
XRotate Object 1, CamX
`Jumping
If Spacekey() = 1 AND Jumping = 0 AND Jump_Timer = 0
Jump = 1
EndIf
` Remstart
If Jump = 1
Ground = PlayerY
Jump_Speed = 2.8
Jumping = 1
Jump = 0
EndIf
` Remend
`Remstart
If Jumping = 1
Dec Jump_Speed, 0.2
Position Object 1, PlayerX, PlayerY + Jump_Speed, PlayerZ
`Remstart
If PlayerY <= Ground
Jumping = 0
Jump_Speed = 0
Ground = 0
PlayerY = Ground
Jump_Timer = 1
EndIf
`Remend
EndIf
`Remend
If Jump_Timer <= 0
Jump_Timer = 0
EndIf
`remstart
If Jump_Timer >= 0.1
Dec Jump_Timer, 0.05
EndIf
`remend
Endfunction
Function Shooting()
If Keystate(19) = 0 AND MouseClick() = 1 ` If Fire Is Pressed
If Ammo > 0
Dec Ammo, 1
EndIf
If Object Exist (2) = 1
If Ammo > 0 AND Intersect Object (2, Limb Position X(1,1), Limb Position Y(1,1), Limb Position Z(1,1), PlayerX, PlayerY, PlayerZ) > 0
Dec EnemyHP, 1
EndIf
EndIf
EndIf
If EnemyHP = 0 AND Object Exist (2) = 1 ` Die
Delete Object 2
Endif
If Object Exist(2) = 1 ` Display Enemy Health
Center Text Object Screen X(2), Object Screen Y(2) - 50, "Enemy Health: " + Str$(EnemyHP)
Endif
` Reload
If Keystate(19) = 1 AND Mouseclick() = 0 AND Ammo < MaxAmmo AND Clips > 0 Then Reload = 1
If Reload = 1 AND (Keystate(19) = 0 OR 1)
Inc ReloadTime, 0.001
If ReloadTime >= 2.5
Ammo = MaxAmmo
Dec Clips, 1
ReloadTime = 0
Reload = 0
EndIf
Endif
Endfunction
Function Ammo_Clip()
If Object Exist (4) = 1
If Ammo < MaxAmmo AND Intersect Object (4, PlayerX, PlayerY - 50, PlayerZ, PlayerX, PlayerY, PlayerZ) > 0
Clips = MaxClips
Ammo = MaxAmmo
Delete Object 4
EndIf
EndIf
IF OBJECT EXIST(4)=1 THEN CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-70, "Ammo Crate"
Endfunction