• Create Account

Member Since 02 May 2001
Offline Last Active May 14 2015 01:56 PM

### Confused about linear forces and rotation

10 March 2015 - 06:48 PM

I'm sure this has been asked 10000s of times before, but I can't find a good explanation.

I saw some code in Box2D for applying a linear impulse (force works similarly) that looks like this (paraphrasing the code):

```ApplyImpulse(Vector2 impulse, Vector2 position)
{
linear_velocity += impulse / mass;
angular_velocity += Cross(impulse, position - center_of_body) / momentOfInertia;
}```

But I don't understand how this works. I have a pen on my desk, and when I apply a force near the center the entire pen moves but doesn't rotate. If I apply the same force at the tip of the pen it rotates but doesn't really move. It looks like this code would handle the pushing-the-pen-near-the-center case, but move the pen way too much in the other case. But then everything that I've read says that this is correct and it's just how it works.

I don't get it.

### Need help with 2D puddle

24 May 2014 - 03:36 PM

In my game kittens can dissolve into a puddle of goop, but I'm not happy with how the puddles look. You can see below.

I'm not sure what I can do to make them look better. How can I represent a puddle in this stylized way that matches the rest of the game on completely flat terrain? Any ideas?

And here is the puddle texture:

### Moving pendulum

23 November 2012 - 01:05 PM

I thought this would be simpler than it has turned out to be. Imagine a string with a heavy weight at one end that's attached to the mouse cursor, and as the player moves the mouse cursor the weight at the end of the string should sway and oscilate around. Creating a simple pendulum is easy, but making the pendulum and the weight move around in response to the movement of the pendulum.... I'm not having any luck. I found this: http://math.stackexc...th-moving-pivot but that diagram doesn't look correct.That angle between A1 and A is not , but rather (right?).

Anyway, here is a snippet of code but it doesn't work. The bob doesn't behave at all like what I want. I call this method each frame, and the coordinates represent the mouse coordinates. I'm not using _bobAngle.Y yet, so ignore the fact that I'm not calculating it. I'm just trying to get the bob to behave correctly in 1 dimension before I work on the second.

[source lang="csharp"]private void update(float elapsedTime, int x, int y){ // figure out the current mouse velocity Vector3 vel = new Vector3(); vel.X = x - _position.X; vel.Y = 0; vel.Z = y - _position.Z; vel *= elapsedTime; // compare the current velocity with the old to calculate acceleration Vector3 acceleration = (vel - _oldVelocity) / elapsedTime; acceleration.Y = -5.0f * elapsedTime; _oldVelocity = vel; float b2 = (float)Math.Atan2(acceleration.X, -acceleration.Y); float a1 = acceleration.Length() * (float)Math.Cos(MathHelper.PiOver2 - Utils.AngleDiff(_bobAngle.X, b2)) * 1.0f; _bobAngularVelocity.X += a1 / _springLength * elapsedTime; // apply damping _bobAngularVelocity -= _bobAngularVelocity * 0.01f * elapsedTime; // apply velocity _bobAngle.X += _bobAngularVelocity.X * elapsedTime; _bobAngle.Y += _bobAngularVelocity.Y * elapsedTime; _bobAngle.X = MathHelper.WrapAngle(_bobAngle.X); _bobAngle.Y = MathHelper.WrapAngle(_bobAngle.Y); _position.X = x; _position.Z = y;}private Vector2 calcBobPosition(){ Vector2 p = new Vector2(); p.X = _position.X + _springLength * (float)Math.Sin(_bobAngle.X); p.Y = _position.Z + _springLength * (float)Math.Sin(_bobAngle.Y); return p;}[/source]

Can anyone tell what I'm doing wrong?

### Framerate independent friction

28 April 2012 - 07:22 PM

I noticed that my game runs a bit differently when running at 60 FPS on my PC and 30 FPS on my phone, and I traced it down to the friction code. I'm applying friction like this:

`newVelocity = oldVelocity - oldVelocity * friction * elapsedTime`

The results are not consistent between 60 Hz and 30 Hz. But then I thought about how continuous compound interest is calculated, and I came up with this:

`newVelocity = oldVelocity * exp(-friction * elapsedTime)`

It works perfectly, at least on paper. Has anyone else ever used an approach like this? Or is there a better way to do it?

Edit: I should mention that the game is using a fixed time step. At 30 Hz it's 1/30 seconds and at 60 Hz it's 1/60.

### How can I improve this song?

13 March 2012 - 10:05 PM

I know absolutely nothing about music composition, and yet I'm attempting to write a song be the theme for a game I'm working on. I was thinking of the old Harvest Moon SNES game when I wrote it, since that's kind of the idea I'm trying to get across.

Anyway, how can I improve the song? It seems so basic and flat. What does it need?

clicky

PARTNERS