Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1364 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: 520

« 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  

EgonOlsen (44 views)
2018-06-10 19:43:48

EgonOlsen (24 views)
2018-06-10 19:43:44

EgonOlsen (46 views)
2018-06-10 19:43:20

DesertCoockie (200 views)
2018-05-13 18:23:11

nelsongames (126 views)
2018-04-24 18:15:36

nelsongames (125 views)
2018-04-24 18:14:32

ivj94 (866 views)
2018-03-24 14:47:39

ivj94 (127 views)
2018-03-24 14:46:31

ivj94 (770 views)
2018-03-24 14:43:53

Solater (142 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

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 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!