I found a game on the Internet called Sagittarius. This game is very fun, and I have a question: how can I make the arrow move like it does in this game? I know each sphere has a different gravity, but when I try to use this formula, it's not working as I expect=. Can any one help me resolve this problem? Thanks.
public List<PlanetABC> p = new List<PlanetABC>() {
new PlanetABC(){
x = 0.91f,
y = -1.28f,
gravity = 5,
r = 5
},
new PlanetABC(){
x = 8.12f,
y = -1.3f,
gravity = 3,
r = 10
}
};
void Start () {
}
void Update () {
float gravityOnX = 0;
float gravityOnY = 0;
foreach (var planet in p)
{
if (Vector2.Distance(g.transform.position, new Vector2(planet.x, planet.y)) > planet.r)
continue;
if (planet.x > g.transform.position.x)
gravityOnX += planet.gravity;
else gravityOnX -= planet.gravity;
if (planet.y > g.transform.position.y)
gravityOnY += planet.gravity;
else gravityOnY -= planet.gravity;
}
if (currentGravityX > gravityOnX)
currentGravityX -= Time.deltaTime;
else currentGravityX += Time.deltaTime;
if (currentGravityY > gravityOnY)
currentGravityY -= Time.deltaTime;
else currentGravityY += Time.deltaTime;
Debug.Log(currentGravityX + "/" + currentGravityY);
var DEG2RAD = Mathf.PI/180;
float vx1 = Mathf.Cos(angle * DEG2RAD) * power ;
float vy1 = Mathf.Sin(angle * DEG2RAD) * power;
float y = (0.5f * currentGravityY * time + vy1) * time;
float x = (0.5f * currentGravityX * time + vx1) * time;
Vector3 pos = g.transform.position;
pos.x = x;
pos.y = y;
g.transform.position = Vector3.Lerp(g.transform.position, pos, Time.deltaTime);
time += Time.deltaTime;
}
Here is the game: https://gprosser.itch.io/sagittarius