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.

Newcomers DBPro Corner / About jump and gravity

Author
Message
Koganwel
13
Years of Service
User Offline
Joined: 27th Jul 2011
Location:
Posted: 11th Sep 2011 03:30
I have two "theoretical" questions to propose to you.


A) At the time of the jump of the player, it seems to to me that the jump is carried out according to an angle as marked as 80 degrees. What gives a jump in acute warhead, i.e. a marked high jump which is summarized with only some steps forwards - approximately three or four widths of the sprite. In reality (let us think of a jumper of distance), the jump is less in height than in distance: the athlete does not even jump to 45 degrees, it would lose over the length of the jump. How to carry out that in programming? I did not know to still find the good algorithm.


B) In reality (always), the gravitation is not that of the planet Jupiter, the return towards the ground is… light - except on the great heights, then the subject can reach a speed of 500 km/h (if I am not mistaken). It seems to to me that my player too quickly crosses the height of the screen to the ground. But to decrease the gravitation does not solve the problem; then, the player tends to jump too high - and it turns over towards the ground at a speed also fulgurating. How can one slow down (a little) the falling speed so that the whole appears… natural?

Thanks to you.
Webber
13
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 12th Sep 2011 01:46
If you want to calculate angles then search the Code Base for 2D, Dark Basic Professional, 360 sprite motion.

Very useful code for calculating angles in 2D games.

As for jumping all you need is:
x( and z) Speed of player
Jump strength
Gravity strength

If you want to adjust the height of the players jump, then just adjust the Jump strength.

If you want to adjust the speed the player falls then change the strength of the gravity.

As for slowing down (a little)
You don't have to use integers, if you want more accurate height adjustments then just use decimals.



I hope that this helps.

I like games, and stuff.
Koganwel
13
Years of Service
User Offline
Joined: 27th Jul 2011
Location:
Posted: 12th Sep 2011 23:31
Thank you, Webber.

Here is my code - for now, it is only a... study. I am learning.



I adjusted the variables related to gravity without obtaining the two required effects: a certain long jump (not only in height) and a reduction falling speed.

But perhaps I create a forgery problem? Possible. I could understand it if such is the case
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 14th Sep 2011 09:59 Edited at: 14th Sep 2011 10:17
Quote: "subject can reach a speed of 500 km/h (if I am not mistaken). "

you may find this info of some use http://hypertextbook.com/facts/JianHuang.shtml That kind of speed is only possible if you start your fall up in the stratosphere where there is very little atmosphere and therefor next to 0 drag. and here's an interesting fact , if you fire a rifel parallel to the ground and drop the same bullet type from the same height as the gunshot at exactly the same time, both bullets hit the ground at the same time.
Webber
13
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 16th Sep 2011 07:01
You can use the sync command for more accurate adjusting of the speed of your program.



I like games, and stuff.
Koganwel
13
Years of Service
User Offline
Joined: 27th Jul 2011
Location:
Posted: 16th Sep 2011 17:59
Hi Webber.

If I does not adjust Sync Rate, the study of bouncing balls in large numbers appear as flashes of color, or the scrolling of a big map is at a crazy speed. I have no choice but to use Sync Rate in that cases. I bought my computer to meet the most demanding games.

However, in this case, even with a Sync Rate = 1000, the movement is almost frozen. A value greater than 1000 equivalent, it seems, to Sync Rate = 0. Sync Rate is not the solution.

stevmjon, of PlayBasic, proposed an algorithm using the COS function to give the jump a circle arc that makes a natural jump. We must therefore resort to trigonometry. God bless me !
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Sep 2011 23:45
@Koganwel, I've had a look at the code you posted and there isn't much wrong with it.

What Webber has been saying about juggling values of jump stength and gravity is correct but I think the issue you may be having is that you have some very small values for the various speed and gravity variables. This could be giving the impression that not a lot is happing when you try to change them.

I'm guessing you've had to do this to stop the player falling through the platforms.

I've modified the code you posted with some tweaks and managed to achieve what I think is pretty good falling speed. I've also modified the collision code slightly to stop the player from falling through the platforms at higher speeds.



Hope this helps.
Webber
13
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 18th Sep 2011 03:04
Hi, I'm back and I modified the collision, and variables even more.
Little glitch's still occur on the corners sometimes, but it does the job.

The collision works in all 4 directions now left right top bottom.

And I made a 2D array for the tiles... not so sure that it was the best idea, it can be a little confusing.

Mario style, except without Mario.


I don't think that you will need sin, cos, tan, etc. trigonometry stuffs, unless you need to make a program that involves firing projectile at a specific angle.

Then what you need to do is take that 360 sprite motion code I told you about so you can get the starting angle of the projectile,
and then add some gravity, and adjust the velocity of the projectile, and finally create a giant robot for the projectile to collide with.
Make sure that there is a big explosion. You could even make random projectile explosion effects too, that would be cool.

Good luck if that what you need to do, but it looks like all you need is to adjust sync rate, and some variables.

I like games, and stuff.
Koganwel
13
Years of Service
User Offline
Joined: 27th Jul 2011
Location:
Posted: 18th Sep 2011 17:48
Webber, I would not know how to thank you for your effort - as TheComet, you are generous of your knowledge. You offer exactly to me what I sought for a long time, but this time in a code easy to understand, effective, being able to be to alter to obtain the required program. (All this " to " are good translation from French ? OMG !)

While 29 games (which I thank) prepared its example, I had discovered that the use of trigonometry was not essential to make jumps more natural, it is initially a question of fine tuning. The speed of the character must be sufficient, if not the jump will have obligatorily an acute angle. In the same way, if the speed is too high, the character will jump half of the screen. Obviously, it is a job of fine tuning of some variables which is the key to success.

I am interested in the programming for the pleasure of creating, I do not have in order to create Terraria II, it is above my competences - but to write a history of 400 or 600 pages, to concoct (devise/invent) a complex scenario, to make live characters with particular agendas, here is my talent. Here what fills my seven days of the week. Programming, and playing (for example the occult Deus Ex: Human Revolution), is a hobby.

The hobbyist thanks you thousand times, Webber.

Login to post a reply

Server time is: 2024-11-24 02:03:24
Your offset time is: 2024-11-24 02:03:24