void newAttract(newAttractor objToAttract) { /*direction = A.position - B.position; * distance = direction.magnitude; * * if (distance == 0f) * return; * * float forceMagnitude = G * (A.mass * B.mass) / Mathf.Pow(distance, 2); * //Debug.Log("Gravity in RB for: " + name + ": " + forceMagnitude); * * GravForce = direction.normalized * forceMagnitude; * Debug.Log("Gravity for RB" + name + " is :" + GravForce); * A.transform.Rotate(rotata * Time.deltaTime); * * /* A.AddForce(-GravForce);*/ //----------------SELF MADE NICELY NICE STUFFY STUFF//------ position = new Vec3(fx, fy, fz); // Planeta petit dir = sunPos - position; dist = Vec3.Distance(sunPos, position); float f = (G * bigMass * mass) / Mathf.Pow(dist, 2); Vec3 gravity = Vec3.Normalize(dir) * f; velocity.x = velocity.x + Time.deltaTime / 20 * gravity.x; velocity.y = velocity.y + Time.deltaTime / 20 * gravity.y; velocity.z = velocity.z + Time.deltaTime / 20 * gravity.z; // position = position + velocity * Time.deltaTime; fx = fx + velocity.x * Time.deltaTime; fy = fy + velocity.y * Time.deltaTime; fz = fz + velocity.z * Time.deltaTime; transform.position = new Vector3(position.x, position.y, position.z); }
void FixedUpdate() { attract = this; newAttract(attract); }