# Tidal/Celestial bodies equations

## Main Question or Discussion Point

I was thinking that it would be cool to be able to create an artificial intelligence for video games which has an understanding of celestial bodies in relation to clumps of enemy units. The enemy units become the celestial bodies, and your units clump to engage them. I would be running the celestial bodies equation for all my counter units, so I would essentially be forking the algorithm multiple times for certain units. Would it be at all possible to get a synopsis of the equations in a packet that a layman can understand? I would essentially need the equation that calculates the tides in relation to the moon, but it would be two dimensional, and would therefore be telling my units what affinity they should have for certain areas of the map. I am a software developer, so if one could explain with very simple and or vocabulary names of the elements of the equation that would be great. Software equations get evaluated backwards, but if you need to do it the other way, that's fine. I would need to know how to scale down to a battlefield approximation.

var num = 1
num = num + 2
num = num * 3

Related Computing and Technology News on Phys.org
Baluncore
2019 Award
The bodies will have velocity in your 2D world, that will change due to gravitational forces of all other bodies or players through the inverse square law. G * M1 * M2 / r^2.
Start here; https://en.wikipedia.org/wiki/Gravitational_field#Classical_mechanics
https://en.wikipedia.org/wiki/N-body_simulation

Or find any book on Orbital or Celestial Mechanics.

If you want our real Solar system predictive computations...
Beginners programming guide here; Astronomical algorithms, by Meeus J. Willmann-Bell, 1991.

• jim mcnamara and anorlunda
I can see that the equation you have given me is Gravity times Mass1 times Mass2 all divided by the radius of my circle squared. Please check that last sentence. I will probably add a scalar multiplier in order to overwhelm forces that approach by a certain factor. Should be simple multiplication. Thanks.

Baluncore
2019 Award
all divided by the radius of my circle squared.
No, divided by the distance between those two masses squared.

Baluncore
2019 Award
You seem to be new to this.
You will need to do vector arithmetic on x and y components.

Define a particle as an object. It has mass m, position px and py, and velocity vx and vy vectors.

For each time step you must;
1. Sum all the force components fx and fy of gravitational forces on each particle, due to all other particles using the force = G.m1.m2 / r2 equation.
2. Use that force and the particle mass to update the particle velocity component vector.
3. Work out the new position of each particle based on last position and velocity.
4. Redraw the screen.

Setup a couple of particles with mass, position and velocity. See if you can simulate one particle orbiting another on the screen.