Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / How can i Make The Player Jump?

Author
Message
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 29th Dec 2014 14:12
Greetings, It is I, Dr. Ivo Eggman

Ive made a very Simple game and I cant Figure
Out how To Make the Player Jump when They
Hit The Space key? Does Anyone Know how to do This?

If so Could You Show me? I can Give The Code so Far if
it Would Help.

Thank you

P.S.
None of you have happened to see
A Blue Hedgehog Around here Have You?

I Am The EGGMAN!
Thats What i Am!
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 31st Dec 2014 15:01
Is there a way to make it so,

When the Spacebar is pressed,
the Player object moves up for
about a second, then keeps moving back
down until an Object is Hit?

If you could Help that would be Great,
Thanks

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Dec 2014 19:33
2d or 3d? Conceptually similar. In either case, you want a change in position over time.



Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 1st Jan 2015 07:34
Do i just paste that code into what Ive got
Or do i need to Edit it?
and the game so far is 3D,

Heres the code so far (I know, its very simple)



When i added your code to it, the player
object wouldn't move or jump. how/where do i
Add the code?

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 3rd Jan 2015 02:55
I'm a little busy right now, but will take a look at your code within the next day or two. Someone else may jump in in the meantime

Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 3rd Jan 2015 06:37
Okay

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 3rd Jan 2015 12:29
Hi,

the latch code works perfectly. You need to edit the latch code, because the "player = 1" in his code, while in your code the "player = 11".

DirectX 9.0c (February 2010)/ DBClassic v1.20
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 3rd Jan 2015 20:27
Do i Just Change the "Position Object 1" to
"Position Object 11"? and Also do i Delete the:

" rem make a 3d object
make object cube 1,10
position camera 0,0,-50 "?

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 4th Jan 2015 12:28
do not ask, trying!

DirectX 9.0c (February 2010)/ DBClassic v1.20
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 4th Jan 2015 15:23
...What Does That Mean..?

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 4th Jan 2015 19:14 Edited at: 4th Jan 2015 19:15
This means that people in the forum are not here to code for you. Make your own tests before asking questions.
If your code does not work, look at the solution:



DirectX 9.0c (February 2010)/ DBClassic v1.20
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 5th Jan 2015 11:48
Alright, Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 6th Jan 2015 08:22
One last Question,

At the Moment You can just walk off the edge of the ground and
keep walking wherever you want, I have Tried many different
ways but cannot get it to work,
How can i make it so the Player object Just keeps
moving down, (Falling)
and when its touching an Object/Collision Box (Floor)
it stops falling, then if you walk off the edge it
Continues to fall again?
If i Explained that Right..

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Jan 2015 20:43 Edited at: 7th Jan 2015 05:02
Hi,

You seem to be a beginner in programming DBC so I'll first refer you to a series of tutorials that should help overall:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

relating to your question: Pretty much everything is determined by where something is in the 3d world. The position of an object usually changes by user interaction or as a result of some other action.

The position(s) of 3d objects can be referenced using OBJECT POSITION X(number), OBJECT POSITION Y(number), OBJECT POSITION Z(number) . Those values will give you the x,y,z coordinates of the object identified by number.

Using that information, you can determine how an object behaves if it reaches a certain position, or is a certain distance away from a position, is a certain height, etc. Often, the values returned by OBJECT POSITION X(), Y and Z are the center of the object. We'll call it the pivot point (i.e. the point that all of the vertices in the object will rotate around).

A sphere, for example, usually will have this pivot point dead center. If the sphere has a diameter of 20 units, then any point on the outside of the sphere is 10 units away from the center. So if you want the sphere to "stand" on the ground and the grounds position is (0,0,0), then you would have to raise the sphere 10 units up because its pivot point (the center) is ten units away from it's outside. The following code puts a sphere on top of a matrix:



How does all this apply to your question? Well, you have to keep track of where your objects are. If they move to a certain position relative to other objects, then you have program a reaction. If our sphere in the example above was to move off of the matrix and fall, then we would have to know:

1. what determines reaching the edge
2. what happens after reaching the edge

Number one can be determined by knowing the size of the matrix and the position of the sphere. I know my matrix is 1000 by 1000 units, and the far left (-x side) and the bottom (-z side) default to 0 . That means that the lowest corner (the pivot point) on the matrix is at (0,0,0) and the farthest corner is at (1000,0,1000).

With that information, I know that if the X and Z position of my sphere is < 0 or it is > than 1000, my sphere is off of the edges of the matrix. Once that occurs, I have to deal with number 2: program what happens next.

In this discussion, I just want the sphere to fall maybe 100 units and then stop. Like the jumping code, we have to change the Y position (the up and down) over time until we reach our destination value.



This isn't your code, but it is the logic of how to determine when an object reaches a certain point and its behavior changes. Before you get into the collision programming, just see if you can master moving to the edges of objects and falling off. That means you'll have to know the sizes of your objects, where they are positioned, and when one object moves "out of bounds" when on top of or next to another object. You could actually handle an object dropping on other obejects without collision detection if you just know the bounds of your objects and keep track of their positions.

Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 7th Jan 2015 06:22
Okay ill take a look at these
and see if i can get it to work
in a couple of days or so

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 8th Jan 2015 14:15
Hey, I will try your Tutorials Soon But,
Do you know if theres a Command to just
Add Artificial Gravity or something like that?

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Jan 2015 18:11
No actually. You have to program and build everything yourself. But usually in DBC 3d the Y axis is up and down. So if you change the Y position over time, you can simulate gravity.

You could set up your own function of a general gravity formula for all objects. I'm not talking about an actual physics simulation, just a manageable change in y position over time. If I have time tonight or tomorrow to knock something together, I'll create an example.

Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 9th Jan 2015 09:46
Alright Thanks!

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Jan 2015 01:43
I had forgotten that there is a pretty good example of collision with gravity and jumping within the example programs in the help file. I'll post it here. run the program, then take a look through the code to try and understand how it was put together:



Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 12th Jan 2015 13:17
Yeah i saw that one and was taking
A Look at it, thats were i saw
The Gravity Command and was wondering
How it Worked?

Such as this one


How does that one work?

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Jan 2015 21:32
This section:



playergrav# is not a command it is a variable. It is a variable that is adjusted to change the players Y position.

posy#=posy#-playergrav# is the expression that adjusts the players Y position variable by the current value of playergrav#.

position object 11,posx#,posy#,posz# moves the player object to the new coordinates stored in the variables posx#,posy#,and posz# . The a collision check is done. The variables are readjusted based on how much the collision detection box around the player object has moved through whatever surface it has collided with. Since the gravity variable is always being subtracted from the Y position, the player will always be colliding with whatever surface it is on.

dec posy#, get collision y() will adjust posy# in the OPPOSITE direction of where it had moved just before by the amount it has penetrated the surface. get collision y() returns the value of penetration in the y direction. dec decrements or subtracts that value from posy#. If the penetration through the surface was -.01, then it will be moved upwards .01 to make the player continue to stand on the surface.

If the player was in the air, then there would be no collision (at least in the y direction) therefore the players ypos# would continue to be decreased by the playergrav# value.

There is no gravity command. All of the adjustments to position are handled by variables that are changed over time.

Enjoy your day.
Dr Eggman
9
Years of Service
User Offline
Joined: 27th Dec 2014
Location: In The Space Coloney Ark
Posted: 13th Jan 2015 07:23
Alright, Ill see if i can Figure this out,

Thank you

Ill Be Back, With a New Robot!
That has Super Laser Eyes,
And He'll Feed me Ham! Evil Ham..

Login to post a reply

Server time is: 2024-04-19 00:52:12
Your offset time is: 2024-04-19 00:52:12