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 Professional Discussion / I don't want code this time, just advice to point me in the right direction

Author
Message
Lee Stevens
19
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Deep in code...
Posted: 7th Sep 2010 01:44 Edited at: 7th Sep 2010 01:45
Hello,

Have a look at the attached file, (its self explanatory) basically you walk along the flatform, you jump, then double jump, then jump over the gap.



I don't want your code otherwise I won't learn i just need to know if what i'm doing is right or not?

I've already make the flatform with (Make Object Box, Commands )

When i jump what is the command that brings the player down to the ground

When i stand on the flatform i dont want to fall through it, is that called collision?

and one last thing whats the command that will stop you running through the walls and when you fall off the ledge what command would tell the computer that you have fallen and must remove 1 live?

Any help would be very appreicated

LS [img]null[/img]

If There Is A Problem, Find The Question.
Lee Stevens 1st September 2007
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 01:53
Quote: "When i jump what is the command that brings the player down to the ground"

You would probably want to make a gravity variable that decreases each loop. This gravity variable is then added to the player's current Y position. If the gravity variable is a negative number, then the player will fall. Once the player hits the ground, this gravity variable should be reset to 0.

Quote: "When i stand on the flatform i dont want to fall through it, is that called collision?"

Yes.

Quote: "and one last thing whats the command that will stop you running through the walls and when you fall off the ledge what command would tell the computer that you have fallen and must remove 1 live?
"

Here you could check and see if the player is below a certain height. If he is, then make him lose a life. You would store the number of lives that the player has left in a variable. Make sure that this height is under all of your platforms so the player can't die while he is still playing. An alternative method would be to check if the player's gravity gets too far into the negative. If it does then he must have been falling for a long time. This means he should lose a life.


Guns, cinematics, stealth, items and more!
Lee Stevens
19
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Deep in code...
Posted: 7th Sep 2010 02:25
Thanks for that sixty Squares
One question if you don't mind, how would i go about creating the gravity?

If There Is A Problem, Find The Question.
Lee Stevens 1st September 2007
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 03:18
You would just make a variable called gravity# or something like that. This variable would keep track of the current gravity amount (the gravity would get more and more powerful each loop since objects fall faster as time goes on). Then you might do something like this:




Guns, cinematics, stealth, items and more!
Fatal Berserker
16
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 7th Sep 2010 07:54 Edited at: 7th Sep 2010 07:54
gravity should be timesed by 0.9 or around that
it is more effective than taking away.
eg
Gravity = Gravity * 0.95
if u wana get exact i think earths gravity would be * 0.98

Smoke me a kipper, ill be back for breakfast.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Sep 2010 11:22 Edited at: 7th Sep 2010 11:26
Quote: "gravity variable that decreases each loop. This gravity variable is then added to the player's current Y position."


Quote: "gravity should be timesed by 0.9 or around that
it is more effective than taking away."


Wow wow guys.

Gravity is a force. A force is not added to a position just like that! (It might work, but the naming is incorrect). That force causes an acceleration. You can calculate the gravity force, by multiplying the object's mass with the strength of the earth's gravity g = 9.81N/kg (F = m*g).

This gravity has an effect on a free body's acceleration. The acceleration can be calculated using Newton's 2nd law F = m*a, which leads to the equation a = -g.

In general, Newton's 2nd law leads to very difficult differential equations which are hard to solve, or not to solve at all. But computers use an easy approximation technique which basically comes down to this:

yAcceleration# = -9.81
ySpeed# = ySpeed# + yAcceleration# * timeElapsed#
yPosition# = yPosition# + ySpeed# * timeElapsed#

Sometimes timeElapsed# (seconds) is taken 1.0, and the gravity is scaled down for compensating that factor (in that case, yAcceleration equals the acceleration in pixels/loop). The equations are wrong then, but still a pretty good approximation in games.

yAcceleration# = -9.81 / Factor#
ySpeed# = ySpeed# + yAcceleration#
yPosition# = yPosition# + ySpeed#

A big difference between those two, is that the first equations are better suited for timer based movement, whereas the second ones are usually chosen for their simplicity.
I recommend using the second version for starters.

Cheers!
Sven B
Sorry if I'm giving too much information. But learning wrong things can make it harder later on.

Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 17:56
Quote: "Wow wow guys."



I was trying to explain things on the simplest terms since Lee is new. I'm not sure he wanted a physics lesson, but you never know .

In any case, your method is extremely similar to mine. All you've done is used two more variables, used Earth's gravity instead of an arbitrary value, and then added Timer Based Movement. You've also provided more detail. I guess that's good for future reference though-- whenever he wants something more advanced he can just come back to this thread. No need to mock us though.


Guns, cinematics, stealth, items and more!
Fatal Berserker
16
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 7th Sep 2010 23:57
Yeah, it was actually momentum that should be multiplied by 0.98, mybad, but...
Lee Stevens for starting off just follow sixties example, its more straight forward.

Smoke me a kipper, ill be back for breakfast.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Sep 2010 13:01
Besides which what's the difference between:
Quote: "gravity#=gravity#-0.10
...Position Object 1,x#,y#+gravity#,z#
"

by @Sixty Squares

...and:
Quote: "ySpeed# = ySpeed# + yAcceleration#
yPosition# = yPosition# + ySpeed#"

...your recommended suggestion @Sven B? Especially if "yAcceleration# = -9.81 / Factor#" happened to work out at about say... -0.10?

Take a look at what you are recommending and what you are saying is incorrect @Sven? They are exactly the same.

Personally I usually use something like what @Fatal Berserker suggested and Newton hasn't turned in his grave yet... to my knowledge...

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Sep 2010 19:24
I agree that the code will do exactly the same. But giving the right meaning to the right variables is pretty important IMHO. Then again, my studies have caused me to notice things like this (or my professors would shoot me) and I probably overreacted.

I'm sorry if I sounded arrogant in any way. It was not my intention to break down you guys' code (hence "(It might work, but the naming is incorrect)"). I just thought the naming of your variables was wrong, and I attached a bunch of needless information instead.

Cheers!
Sven B

Login to post a reply

Server time is: 2026-07-22 12:41:18
Your offset time is: 2026-07-22 12:41:18