Physics: trajectory, axis, lever

Started by rbaleksandar, Thu 05/02/2009 19:38:11

Previous topic - Next topic

rbaleksandar

Hi, guys  ;)

  Well, I have a very complicated problem here (at least from my point of view, since physics isn't my strength so to speak  ;D). I am trying to make a separate small game (kind of experiment) that I'll probably include in on project of mine, that is still just an idea in my twisted mind but I hope it'll become something big and fun to play ;) Ideas needed :)

  What you see down here is what I'm interested in (it's just a sketch)  :=



  Now I want to say in advance - please, don't expand some complicated physics theory about the order in the Universe  ::) Because I won't get it...Fast enough. And I'll start asking silly questions.

  And there we go. My character X enters a cave or something. From left to right (look at the picture; didn't draw everything, only the catapult system). There is an entrance somewhere on the right high above the ground. Now the only way for X to reach this spot is for X to catapult himself using a beam, a small stone (as axis) and a weight (bigger stone). What X can do with this things:
beam and axis are already placed; but he can of course push the axis (for example the given 4 positions (in purple) - I'll probably make them 3 because the more different positions of the axis, the more trajectories => more stuff to draw and animate  :P). The big rock is thrown by X with a constant force at the same place each time - the right end of the beam, so the animation here will be the same each time.


My ideas:

1) Same animation for throwing the stone;
2) n different "flights" with different trajectories for each of the n positions of the axis;
3) Same animation for the character to go (if catapulting didn't succeed and he fell back on the ground :)), pick up the stone that's fallen on the ground near the right end of the beam and return to his previous position on the left end of the beam for another go;
4) n different views for each of the n positions of the axis and beam;


  So...What do you think? The complicated scripting will be avoiding with more animations and simple commands like going to a curtain position (x,y) etc. Would also like to know if I've missed some important aspect of this experiment, since I want to make it as real as possible (I mean the physics of course ;)).


Thanks for the support in advance.
Best regards,
rbaleksandar
I am a mighty pirate. Arrrrgh!

Khris

First of all: you won't need n different animations.
Even if you did this using animations only (as opposed to calculating the stone's and guy's trajectory), all that'll change with the position of the axis is the starting x coordinate.

Animations are always run relative to the starting point of the object that animates anyway.

I'll try out a few things and get back to you.

rbaleksandar

#2
Quote from: KhrisMUC on Thu 05/02/2009 20:41:24
First of all: you won't need n different animations.
Even if you did this using animations only (as opposed to calculating the stone's and guy's trajectory), all that'll change with the position of the axis is the starting x coordinate.

Animations are always run relative to the starting point of the object that animates anyway.

I'll try out a few things and get back to you.

:)

Thanks but I do think now I definitely need these different animations since it's kind of physical rule (lever, axis etc.):
The closer the axis (the small stone) to the one end of the beam is, the more difficult it is to lift the object on the other end. So if the axis in position 2 and then in position 3, we'll get different push-power (dunno how it's in English :P), so with less push power (position 2), the character will be catapulted with less power, so it'll land sooner and his trajectory will be different from the one with axis on position 3 (with more push-power). Is that right? We're talking about pure physics here, so - as I said - I'm not sure if all that I'm talking about, is right, but I've just done an experiment with a pencil and two rubber, and it worked as I've described it.



btw I've decided to make it even more realistic :D If X throws the stone and the axis is on position 3, the beam will break  ;D Here comes of course another problem :( How many positions will be most appropriate and which one (or more) would be most suitable to break?
I am a mighty pirate. Arrrrgh!

Khris

Ah, I see, I thought the beam is moving along with the axis.
It's pretty late here, I might get back to this tomorrow.

rbaleksandar

I am a mighty pirate. Arrrrgh!

R4L

I'm interested as to how this would go...

Also, I think this should be moved to the Tech Forum.

rbaleksandar

#6
Well, as I said this are mostly animations on my opinion. Sure there is scripting, but not to much. It could be probably done with more scripting, less animations, but...Don't know how :) So the place is good ;)

btw Added "and beam" in point 4).
I am a mighty pirate. Arrrrgh!

rbaleksandar

Oh, well, obviously will have to solve this alone...
I am a mighty pirate. Arrrrgh!

beomoud

#8
I haven't tried this but this is what comes to mind

float ang;
float x_mov;
float x_center;
float y_center;
float radius;//changeradius to correspond for different axis point
float a;//change a to correspond for different axis point and to make a more realistic parapolic movement
...
repeatedly execute:
x = FloattoInt(x_mov * a);
y = FloattoInt(Maths.Sqrt(Maths.RaiseToPower((x_mov - x_center),2.0) - Maths.RaiseToPower(radius)) - y_center);
x_mov++;

OR

x = FloattoInt(Maths.Sin(Maths.DegreesToRadians(180 - angle)) *radius - x_center) + a *x_mov;
y = FloattoInt(Maths.Cos(Maths.DegreesToRadians(180 - angle)) *radius - y_center);
if (angle >= 0)
angle++

(x and y are cRock.x and cRock.y)

beomoud

ask me to explain anything you don't understand

rbaleksandar

Thanks!

Quotey = FloattoInt(Maths.Sqrt(Maths.RaiseToPower((x_mov - x_center),2.0) - Maths.RaiseToPower(radius)) - y_center);
I don't understand this. The second method seems to be easier but first I want to understand this (will implement all that with my own code ;)).
In the help I found the description
Quotefloat Maths.RaiseToPower(float base, float exponent)

Calculates the value of base raised to the power exponent.
This means that base is multiplied by itself exponent times.

  But why do we do that? Some complicated physical rule or what? The whole line looks complicated :)
  Second thing I don't understand is why we round the results? Don't we loose precision by doing that?
I am a mighty pirate. Arrrrgh!

beomoud

#11
No it's not a physical rule, if you want to do it physically you would have to built a physics engine and that is beyond me at this point. It's just simple math:

I haven't tried them yet but they just give you a circular movement and you can control where the trajectories land. The first one is the equation of a circle (y2-y1)raise_to_2 + (x2-x1)raise_to_2 = (radius)raise_to_2

the second just give's you the x and y as a vector from the center of a circle to a point on the circle changes it's angle:
y = cos(f)
x = sin(f)

here's another one if you want a more periodic movement:

if (y > = 0){
x = x_mov *a; //a changes the speed
y = FloattoInt(Maths.Sin(Maths.DegreesToRadians(x_mov + 2 *Maths.Pi))) *b; //b is a value that changes your y, if b was 1 then the values of y would be 0 to 1.

x_mov++;
}

Oh and you don't really need decimal precision for the x and t coordinates, it only takes intergers as it's values

if you want to do it with physics (i wouldn't recommend it) take a look at this:

http://en.wikipedia.org/wiki/Trajectory

oh and of course it is nice that you want to write your own code, me as well have never put anything in my code that i don't understand...
:)

rbaleksandar

Thank a lot! Well, you know it's much more difficult with physics, I think I might ask my physics teacher for this trajectory thing ;) But first I'll try it with the not-so-complicated solution ;)

But I have to ask something. How exactly do you manage to define the catenary (that is the trajectory) in that circle...I still can't quite get this.
Take a look at his picture:



Now we have an imaginary circle (half of which is in the ground). The center of the lever should be the center of this circle (sorry, draw it very inaccurate :)). So points 1 and 2 (start and end of the flight of our object) make a catenary with center angle (1 ; center of the lever ; 2). So how do you describe this in you code? And how do you make the trajectory of the character that flies up in the sky when the stone hits point 2? After all, it's not a part of a circle. It's a parabol...

  As I write this, I do think it'll be best to describe it with some physics in code...It would be much more accurate. I do believe the trajectory that your code describes is a catenary of a circle and in real world it's parabol or something. It'll take looong time for me to code this, but I hope it'll be worth the work ;)
I am a mighty pirate. Arrrrgh!

beomoud

#13
if you play with the a and b values you'll get a somewhat parabolic movement, so you will if you use the last code with the sin equation.

rbaleksandar

#14
Thanks! I'll keep asking though ;) Problems always occur :)

PS: I do believe there are lots of AGS fans, who want to implement something like that :) So I'll try to make it and post it here along with the source. But that'll last 2 months and something because I'm really busy right now.  8)
I am a mighty pirate. Arrrrgh!

Khris

I tried to calculate the initial x and y momentum based on a given start and end point but I must have screwed up somewhere because the ball misses the target by a good deal.

Anyway, to get a realistic movement, do something like this:

Pseudo-
Code: ags
mx = 3.0;
my = -6.0;

// loop

  my = my + 0.1;  // gravity
  x += mx;
  y += my;
  // draw at x,y

// end loop

rbaleksandar

#16
Can it be from the rounded value of the gravity?
And why do you start with a negative y-coordinate?

let suppose we loop your block till x reaches 15.0 and y reaches +5.0 (hope I didn't miscalculate somewhere :)):

x=3.0;y=-6.0
x=4.0;y=-5.1
x=5.0;y=-4.2
x=6.0;y=-3.3
x=7.0;y=-2.4
x=8.0;y=-1.5
x=9.0;y=-0.6
x=10.0;y=0.5
x=11.0;y=1.6
x=12.0;y=2.7
x=13.0;y=3.8
x=14.0;y=4.9
x=15.0;y=5.0.

Try to draw this on paper...Very strange trajectory. It goes from:

x ; -y

to

x; +y

So it climbs higher and higher until it reaches the point that we gave in the loop. Something like this:




So it seems from your pseudo-code that the object never falls on the ground. ???
It'll be nice to post a screen shot :)
I am a mighty pirate. Arrrrgh!

Khris

You got it all wrong; first of all, all variables are floats, they are only converted to ints at the drawing stage.

Most importantly though, x;y is the starting position of the rock, mx;my is the movement per game loop.

Suppose the rock started at 100;100:

100.0;100.0  -> +3.0, -5.9
103.0;94.1;   -> +3.0, -5.8
106.0;88.3;   -> +3.0, -5.7
109.0;82.6;   -> +3.0, -5.6
112.0;87.0;   -> +3.0, -5.5
...


rbaleksandar

Aaaah, that's something else :) Sorry.
I am a mighty pirate. Arrrrgh!

rbaleksandar

Hm...Still not clear.

So you have this:

100.0;100.0  -> +3.0, -5.9
103.0;94.1;   -> +3.0, -5.8
106.0;88.3;   -> +3.0, -5.7
109.0;82.6;   -> +3.0, -5.6
112.0;87.0;   -> +3.0, -5.5
...

Still the trajectory seems somehow upside down :)

A more detailed resume :)

100.0;100.0  -> +3.0, -5.9 (start point)
103.0;94.1;   -> +3.0, -5.8(forward on abscissa; downward on the ordinate)
106.0;88.3;   -> +3.0, -5.7(forward on abscissa; downward on the ordinate)
109.0;82.6;   -> +3.0, -5.6(forward on abscissa; downward on the ordinate)
112.0;87.0;   -> +3.0, -5.5(forward on abscissa; upward on the ordinate - here is I think a little type mistake since we have 82.6-5.6=77.0)
...
At some point y will get positive (we see that we have -5.9,-5.8,...,-0.1,0.0,+0.1,+0.2,...) and the object will go in the positive direction of x and y.

So the parabola's pick points downwards... This might get fixed if we begin with a negative y.

???
I am a mighty pirate. Arrrrgh!

SMF spam blocked by CleanTalk