Skip to content

[Feature request] Distance-based force #20

@redblobgames

Description

@redblobgames

The current simulation applies a force that is independent of distance. If the distance is 3 or 30 the force applied is the same.

suppose dx = 3 ; dy = 0
then r = sqrt(dx*dx + dy*dy) = 3
then fx  = dx / r = 1

or

suppose dx = 30 ; dy = 0
then r = sqrt(dx*dx + dy*dy) = 30
then fx  = dx / r = 1

There is a force that does not depend on distance, and then stops at some threshold; it is the Strong force, but it is mainly for the quarks inside an atom nucleus, not for artificial life. It would be interesting to use some force that depends on distance, because that would apply to real life forms. Maybe 1/d² (gravity, electromagnetism in a 3d world), 1/d (gravity or electromagnetism in a 2d world), van der waals force which can take into account the size of the particles, or Lennard-Jones which is the force between molecules. The interesting thing with Lennard-Jones is that at close distances it pushes molecules apart and at far distances it pulls them closer. This can create really interesting patterns. There is also a generalization of Lennard-Jones called Mie potential that might be useful for adapting Lennard-Jones to work in 2d.

Before you try these, I have to warn: I did try some of these and I think it will be a bit of work. It is easy to change the formula in the code. But I think all the other numbers in the code like the 0.5 and the -100 to +100 values and the G / -100 are all designed to work with the original distance-irrelevant force, and I think all of those would have to be somehow tweaked to handle distance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions