1. When you jump, you have to alter the Y position of the object in 3D space at the same time as continuing in the current direction and playing the jump animation.
To make it look more realistic, you don't just set the Y position to the 'top' value, you change it gradually. Start by having a very small floating point value in a variable (like Velocity# = .1) which you add to the object's Y position.
You then add to the velocity value during the jump giving the appearence of acceleration.
When it reaches a certain height, you start reducing the value of velocity so the accelleration decreases. This gives the effect of gravity taking effect.
If you continue decreasing the velocity, it eventually becomes negative and applying this to the object's Y position will make it fall back down to earth - increasing in speed as it would in real life. Stop altering the object's Y position when you hit the floor and reset the velocity value ready for the next jump.
Some example code (deliberately simplified to demonstrate the principle):
Sync On: Sync Rate 60
CLS 0
Make Matrix 1,1000,1000,50,50
Make Object Cube 1,3
Velocity# = .01
ObjPosX# = 500.0
ObjPosY# = 3.0
ObjPosZ# = 500.0
Speed# = 0.0
Position Object 1, ObjPosX#,ObjPosY#,ObjPosZ#
True = 1: False = 0
JumpingInProgress = False
Do
If Upkey() = 1
Inc Speed# ,0.1
If Speed# > 4.0 Then Speed# = 4.0
Move Object 1,Speed#
Else
Dec Speed# ,0.1
If Speed# < 0.0 Then Speed# = 0.0
Move Object 1,Speed#
Endif
If Leftkey() = 1 Then YRotate Object 1,Wrapvalue(Object Angle Y(1)-3)
If Rightkey() = 1 Then YRotate Object 1,Wrapvalue(Object Angle Y(1)+3)
ObjPosX# = Object Position X(1)
ObjPosY# = Object Position Y(1)
ObjPosZ# = Object Position Z(1)
If SpaceKey() = 1
If JumpingInProgress = False Then JumpingInProgress = True: GoingUp = True
Endif
If JumpingInProgress = True Then Gosub Jump
Rem SET CAMERA TO FOLLOW X, Y, Z, Angle, Camdist, Camheight, Camsmooth, ColFlag
Set Camera To Follow Object Position X(1), Object Position Y(1), Object Position Z(1), Object Angle Y(1), 20, 10, 10, 0
Sync
Text 0,0,"Speed: "+Str$(Speed#)
Loop
End
Jump:
If ObjPosY# < 7.0 and GoingUp = True
Inc Velocity#, 0.1
Else
GoingUp = False
Endif
If ObjPosY# >= 7.0 and GoingUp = False
Dec Velocity#, 0.2
Endif
Inc ObjPosY#,Velocity#
If ObjPosY# <= 3.0 and GoingUp = False
ObjPosY# = 3.0
Velocity# = 0.1
JumpingInProgress = False
Endif
Position Object 1, ObjPosX#,ObjPosY#,ObjPosZ#
Return
2. If you need a key to be held down rather than just pressed and released to do something, then simply use a Repeat Until loop something like this:
I$ = Inkey$()
If I$ = " "
Repeat
Rem Program will loop in here until space bar is released
Gosub WhateverYouWantToDoWhileSpaceIsHeldDown
Until Inkey$() <> " "
Endif
TDK_Man