|
-
Dec 31st, 2002, 03:24 PM
#1
Thread Starter
Junior Member
character jump
I am making a game in 2d environment with a 2d character that moves left and right only. I want to make him jump, but have no Idea how to make him, even then if he jumps how would you make him land on a platform above the ground?................need help
-
Dec 31st, 2002, 10:01 PM
#2
Frenzied Member
you'll need a loop where the movement code is....
then in the loop you'll have to check for collition with any platform in the game...
here you can get some code for jumping: http://www.vbforums.com/showthread.p...hreadid=221891
-
Jan 2nd, 2003, 11:56 PM
#3
Frenzied Member
This code will make you jump:
VB Code:
Gravity = 0.5
YSpeed = 20
And this you run every frame to continue the jump, if needed:
VB Code:
If NotOnGround = True Then
YSpeed = YSpeed - Gravity
End If
Y = Y - YSpeed 'If it jumps "down" or gives you any error, try changing this to + instead
Of course, you need to set NotOnGround to False if it's not colliding with the ground. A very simple way to do this is check if the Y is smaller than a certain value, like this:
VB Code:
If Y < 100 Then
NotOnGround = True
Else
NotOnGround = False
End If
'Now that we know if it's on ground or not, you can run the code I gave you above
That should do it! Remember that the variables must be accessible from all Subs. You know about variables' scopes right? Oh, feel free to modify those values, this code I gave you might not even work at all unless you adjust them a little...
-
Jan 2nd, 2003, 11:58 PM
#4
Frenzied Member
One more thing, look for the Lander Game Tutorial at vbworld.net , it explains physics like jumping and falling in a very accessible way. (so YOU can understand it better, k? )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|