Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Calculate required impulse to reach the spot.  (Read 721 times)
0 Members and 1 Guest are viewing this topic.
Offline xor_

Innocent Bystander

« Posted 2017-06-15 14:12:42 »

Good day friends.Around three days can`t resolve a problem with impulse calculation(Porbably because my physics knowledge is very poor).

In Figure 1(Fig.1) and Figure 2(Fig.2) are conditions which requires to calculate Velocity of a body for succesefull landing.

What we know:

Question is : How to calculate  velocity to reach the spot?

I have been searching before posting this topic but found nothing(maybe i didn't realize that problem is similar?!).
Thanks for your time!
Offline KaiHH

JGO Kernel

Medals: 446

« Reply #1 - Posted 2017-06-15 18:06:57 »

If you think of your angry circular player as a "bullet" and given that it always jumps with the same velocity magnitude/speed you can search for "ballistic trajectory angle to target" and get:
This gets you the angle at which to jump (relative to the horizontal x axis) given the delta x and delta y between the position to jump from and the target landing position.
In Java this works like this:
float g = 9.81f; // <- acceleration of gravity
float dx = targetPosition.x - playerPosition.x;
float dy = targetPosition.y - playerPosition.y;
float v = 20.0f; // <- magnitude of jump velocity
float v2 = v * v;
float sqrt = (float) Math.sqrt(v2 * v2 - g * (g * dx * dx + 2 * dy * v2));
// If it is possible to reach the target, you'll always get two possible shot/jump angles.
// One for an indirect "high arc" shot and one which is most direct "low arc".
float hiangle = (float) Math.atan2(v2 + sqrt, g * x); // <- "high arc" angle
float loangle = (float) Math.atan2(v2 - sqrt, g * x); // <- "low arc" angle
// If it is not possible to jump to the target, you'll get NaN
// If you are not so much into angles, but prefer vectors, then your jump direction is:
Vector jumpHi = normalize(vector(g * x, v2 + sqrt));
Vector jumpLo = normalize(vector(g * x, v2 - sqrt));
Offline abcdef
« Reply #2 - Posted 2017-06-15 18:28:21 »

You need to split your equations in to two and work out the velocity where they are both equal.

The horizontal equation, assuming no air resistance

distanceHorizontal = initial velocity(horizontal) * time

You can reach arrange and work out the time t to travel horizontally to your chosen spot.

The vertical equation assuming gravity

distanceVertical = initial velocity(vertical) * time - (1/2)*gravityAcceleration * time * time

Again you can rearrange to get the time on one side (just a simple quadratic).

Now you have two equations in t, now find the velocity values which give you the same t for a given distance in the horizontal and vertical

I haven't given you the answer (as I am on my phone) but hopefully you have enough to go on to work this out yourself
Pages: [1]
  ignore  |  Print  

Ecumene (52 views)
2017-09-30 02:57:34

theagentd (76 views)
2017-09-26 18:23:31

cybrmynd (183 views)
2017-08-02 12:28:51

cybrmynd (182 views)
2017-08-02 12:19:43

cybrmynd (189 views)
2017-08-02 12:18:09

Sralse (197 views)
2017-07-25 17:13:48

Archive (747 views)
2017-04-27 17:45:51

buddyBro (881 views)
2017-04-05 03:38:00

CopyableCougar4 (1429 views)
2017-03-24 15:39:42

theagentd (1319 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!