how to let a ball fly like a ball

Started by Miori, Tue 17/05/2011 22:38:09

Previous topic - Next topic

Kweepa

A golf ball trajectory doesn't look like a parabola.
This page might help:
http://www.golf-simulators.com/physics.htm
Still waiting for Purity of the Surf II

Ryan Timothy B

Quote from: Calin Leafshade on Wed 18/05/2011 11:14:59
I actually half started an interface for Box2D. The format of that library makes it very AGS friendly.

I would definitely use that plugin. But since AGS is now open-sourced, we may not need to have it as a plugin.

And yes. I would have a huge use for Box2D in AGS. Maybe not for your standard adventure game, but for other projects I've been dreaming of making.

Calin Leafshade

Ahhh, I would advise against that.

We shouldn't add loads of tenuous shit to the engine for the sake of it.

What we should do however is expand the plugin system and make it cross platform and *then* add physics using that system.

Snarky

Yeah, I don't think we should bundle a physics engine with AGS unless there's actually significant proven demand for one. (And even then it would probably be better to modularize the engine through the plugin system.) If we could have a plugin first, we can see how much use it gets. I haven't had time to look at Khris's example, but I'd much appreciate any module/plugin code either of you get to a releasable state.

Quote from: Miori on Wed 18/05/2011 20:58:23
Ah, I think I understand it better now, even if not completely. I'm happy its working now, also that could make it faster. No slow-motion flying ball anymore  ;D

But could I bother you with another question? How can I make the function stop? I mean, you see the hill on my screenshot. A variable has to be true, when the shot begins. I made a collidingwithobject function, that makes this variable false, to stop it and do other things. It works, but not until the ball reached the target.

With other words: Can I abort the while-process, before it reaches the target?

It's possible (add an additional check in the while condition), but like I said above, the more fancy you want to get, the more it makes sense to go with Khris's proposal, because you can extend it cleanly to cover all sorts of things (like Kweepa's non-parabolic trajectories) and cases you haven't thought of, instead of having to add special hacks for everything that might happen.

Ryan Timothy B

Oh I didn't mean as an actual version that is released on the website as AGS already is. I meant as a separate engine designed for arcade games.
But I know it has been expressed that AGS shouldn't go into different paths, but I don't see a problem with an arcade AGS engine.

Rocco

Quote from: Khris on Wed 18/05/2011 13:01:11
This is how far I got a few days ago; I still have to implement rolling though. It's pretty modular but the ball occasionally drops through the lines so I'd rather not publish it yet.
Tap Space to hurl the ball upwards, F9 restarts, Esc quits.

Hey Khris, great example, would love to see the code for this.   :)

Kweepa

Here's something to get you started using the Magnus effect:
float bx, by;
float dx, dy;
float av;

float airDensity = 1.225; // kg/m^3
float ballRadius = 0.02055; // m
float ballMass = 0.05; // kg
float dragCoeff = 0.5; // ball drag coefficient
float gravity = 9.8; // m/s^2

function room_RepExec()
{
  // use bearman and harvey
  float streamArea = Maths.Pi * ballRadius * ballRadius;
  float ddConstant = airDensity*streamArea/(2.0*ballMass);
  float dt = 0.025; // s

  // simulation step
  float vel2 = dx*dx + dy*dy;
  float vel = Maths.Sqrt(vel2);
  // calculate magnus effect
  float liftCoeff = av*vel/700.0;
  float cosAlpha = dx/vel;
  float sinAlpha = dy/vel;
  float ddx = -ddConstant*vel2*(dragCoeff*cosAlpha + liftCoeff*sinAlpha);
  dx = dx + ddx*dt;
  bx = bx + dx*dt + 0.5*ddx*dt*dt;
  float ddy = ddConstant*vel2*(liftCoeff*cosAlpha - dragCoeff*sinAlpha) - gravity;
  dy = dy + ddy*dt;
  by = by + dy*dt + 0.5*ddy*dt*dt;
  
  // bounce - depends on spin
  if (dy < 0.0 && by < 0.0)
  {
    vel = 0.7*Maths.Sqrt(dx*dx + dy*dy);
    // rotate a bit depending on the angular velocity
    float alpha = Maths.ArcTan2(-dy, dx);
    alpha = alpha + (av*av)/1000.0;
    dx = vel*Maths.Cos(alpha);
    dy = vel*Maths.Sin(alpha);
    av = 0.5*av;
  }
  
  // draw
  DrawingSurface *ds = Room.GetDrawingSurfaceForBackground();
  ds.DrawingColor = 7;
  ds.DrawPixel(FloatToInt(bx), FloatToInt(200.0-by));
  ds.Release();
}

function room_Load()
{
  // driver
  float launchSpeed = 150.0; // mph
  float launchAngle = 7.0; // degrees
  float spin = 3600.0; // rpm

  // 5 iron
  launchSpeed = 100.0;
  launchAngle = 30.0;
  spin = 7200.0;

  float vel = (1602.0/3600.0)*launchSpeed;
  float alpha = Maths.DegreesToRadians(launchAngle);

  bx = 0.0;
  by = 0.0;
  dx = vel*Maths.Cos(alpha);
  dy = vel*Maths.Sin(alpha);
  av = spin * 2.0 * Maths.Pi / 3600.0;
}
Still waiting for Purity of the Surf II

Dualnames

When all else fails SteveMcCrea ALWAYS PREVAILS. God, how are you so awesome?!!!! Please make a tutorial with details on how to become awesome. ;)
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk