Download

Simple Gravity Sim Going Arry

This is my first UE4 Script.



// Fill out your copyright notice in the Description page of Project Settings.

#include "Components/SphereComponent.h"
#include "Planet.h"
#include <iostream>

#define G 100 // N m^2 kg^-2

// Sets default values
APlanet::APlanet()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Mass = 1;
	Velocity = FVector(0, 0, 0);

	Root = CreateDefaultSubobject<USphereComponent>(TEXT("Root"));

	RootComponent = Root;

	SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
	SphereVisual->AttachTo(RootComponent);
	static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
	if (SphereVisualAsset.Succeeded())
	{
		SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
		SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
		SphereVisual->SetWorldScale3D(FVector(0.8f));
	}
}

// Called when the game starts or when spawned
void APlanet::BeginPlay()
{
	Super::BeginPlay();

}

// Called every frame
void APlanet::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FVector my_location = GetActorLocation();
	float m0 = Mass;
	float x0 = my_location.X, y0 = my_location.Y, z0 = my_location.Z;
	for (TObjectIterator<APlanet> Itr; Itr; ++Itr) {
		if (Itr->IsA(APlanet::StaticClass()))
		{
			if (*Itr != this) {
				FVector other_location = Itr->GetActorLocation();
				float m1 = Itr->Mass;
				float x1 = other_location.X, y1 = other_location.Y, z1 = other_location.Z;
				float dx = x1 - x0, dy = y1 - y0, dz = z1 - z0;
				float rsquared = FMath::Pow(dx, 2) + FMath::Pow(dy, 2) + FMath::Pow(dz, 2);
				if (rsquared > 0) {
					float r = FMath::Sqrt(rsquared);
					float force_between = G * m0 * m1 / rsquared;
					float acceleration_norm = force_between / m0;
					float x_hat = dx / r, y_hat = dy / r, z_hat = dz / r;
					UE_LOG(LogTemp, Display, TEXT("x0, y0, z0 = %f, %f, %f"), x0, y0, z0);
					UE_LOG(LogTemp, Display, TEXT("x1, y1, z1 = %f, %f, %f"), x1, y1, z1);
					UE_LOG(LogTemp, Display, TEXT("dx, dy, dz = %f, %f, %f"), dx, dy, dz);
					UE_LOG(LogTemp, Display, TEXT("xh, yh, zh = %f, %f, %f"), x_hat, y_hat, z_hat);
					UE_LOG(LogTemp, Display, TEXT("rsquared = %f"), rsquared);
					UE_LOG(LogTemp, Display, TEXT("r = %f"), r);
					UE_LOG(LogTemp, Display, TEXT("force_between = %f"), force_between);
					UE_LOG(LogTemp, Display, TEXT("acceleration_norm = %f"), acceleration_norm);

					Velocity.X -= x_hat * acceleration_norm * DeltaTime;
					Velocity.Y -= y_hat * acceleration_norm * DeltaTime;
					Velocity.Z -= z_hat * acceleration_norm * DeltaTime;
				}
			}
		}
	}
	my_location.X += Velocity.X * DeltaTime;
	my_location.Y += Velocity.Y * DeltaTime;
	my_location.Z += Velocity.Z * DeltaTime;
	SetActorLocation(my_location);
}


I’ve got two “APlanet”'s of my own making. Simple spheres with a mass of 1 and a starting velocity of 0. I expect them to come together over time.

The output looks like this:



[2020.07.31-03.45.26:620][392]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.26:620][392]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.26:620][392]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.26:621][392]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.26:621][392]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.26:621][392]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.26:621][392]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.26:621][392]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.30:267][392]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.30:268][392]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.30:268][392]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.30:268][392]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.30:268][392]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.30:268][392]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.30:269][392]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.30:269][392]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.30:980][392]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.30:981][392]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.30:981][392]LogTemp: Display: dx, dy, dz = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.30:981][392]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.30:981][392]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.30:981][392]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.30:981][392]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.30:981][392]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.31:692][392]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.31:692][392]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.31:693][392]LogTemp: Display: dx, dy, dz = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.31:693][392]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.31:693][392]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.31:693][392]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.31:693][392]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.31:694][392]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.32:381][393]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.32:382][393]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.32:382][393]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.32:382][393]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.32:382][393]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.32:382][393]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.32:383][393]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.32:383][393]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.33:095][393]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.33:095][393]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.33:096][393]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.33:096][393]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.33:096][393]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.33:096][393]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.33:096][393]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.33:096][393]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.33:706][393]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.33:706][393]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.33:706][393]LogTemp: Display: dx, dy, dz = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.33:707][393]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.33:707][393]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.33:707][393]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.33:707][393]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.33:707][393]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.34:316][393]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.34:316][393]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.34:316][393]LogTemp: Display: dx, dy, dz = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.34:317][393]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.34:317][393]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.34:317][393]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.34:317][393]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.34:317][393]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.34:944][394]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.34:944][394]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.34:944][394]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.34:944][394]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.34:945][394]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.34:945][394]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.34:945][394]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.34:945][394]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.35:604][394]LogTemp: Display: x0, y0, z0 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.35:604][394]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.35:605][394]LogTemp: Display: dx, dy, dz = -290.000000, 530.000000, 170.000000
[2020.07.31-03.45.35:605][394]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.35:605][394]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.35:605][394]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.35:605][394]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.35:605][394]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.36:165][394]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.36:165][394]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.36:166][394]LogTemp: Display: dx, dy, dz = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.36:166][394]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.36:166][394]LogTemp: Display: rsquared = 393900.000000
[2020.07.31-03.45.36:166][394]LogTemp: Display: r = 627.614502
[2020.07.31-03.45.36:166][394]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.36:166][394]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.36:777][394]LogTemp: Display: x0, y0, z0 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.36:777][394]LogTemp: Display: x1, y1, z1 = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.36:777][394]LogTemp: Display: dx, dy, dz = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.36:778][394]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.36:778][394]LogTemp: Display: rsquared = 393900.187500
[2020.07.31-03.45.36:778][394]LogTemp: Display: r = 627.614685
[2020.07.31-03.45.36:778][394]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.36:778][394]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.37:431][395]LogTemp: Display: x0, y0, z0 = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.37:431][395]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.37:431][395]LogTemp: Display: dx, dy, dz = -290.000061, 530.000122, 170.000046
[2020.07.31-03.45.37:431][395]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.37:431][395]LogTemp: Display: rsquared = 393900.187500
[2020.07.31-03.45.37:432][395]LogTemp: Display: r = 627.614685
[2020.07.31-03.45.37:432][395]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.37:432][395]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.38:044][395]LogTemp: Display: x0, y0, z0 = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.38:044][395]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.38:045][395]LogTemp: Display: dx, dy, dz = -0.000061, 0.000122, 0.000046
[2020.07.31-03.45.38:045][395]LogTemp: Display: xh, yh, zh = -0.423999, 0.847998, 0.317999
[2020.07.31-03.45.38:045][395]LogTemp: Display: rsquared = 0.000000
[2020.07.31-03.45.38:045][395]LogTemp: Display: r = 0.000144
[2020.07.31-03.45.38:045][395]LogTemp: Display: force_between = 4825805824.000000
[2020.07.31-03.45.38:045][395]LogTemp: Display: acceleration_norm = 4825805824.000000
[2020.07.31-03.45.38:658][395]LogTemp: Display: x0, y0, z0 = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.38:658][395]LogTemp: Display: x1, y1, z1 = -0.000076, 0.000139, 0.000044
[2020.07.31-03.45.38:658][395]LogTemp: Display: dx, dy, dz = -290.000122, 530.000244, 170.000092
[2020.07.31-03.45.38:659][395]LogTemp: Display: xh, yh, zh = -0.462067, 0.844467, 0.270867
[2020.07.31-03.45.38:659][395]LogTemp: Display: rsquared = 393900.343750
[2020.07.31-03.45.38:659][395]LogTemp: Display: r = 627.614807
[2020.07.31-03.45.38:659][395]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.38:659][395]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.40:076][395]LogTemp: Display: x0, y0, z0 = -0.000076, 0.000139, 0.000044
[2020.07.31-03.45.40:076][395]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.40:077][395]LogTemp: Display: dx, dy, dz = 0.000076, -0.000139, -0.000044
[2020.07.31-03.45.40:077][395]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.40:077][395]LogTemp: Display: rsquared = 0.000000
[2020.07.31-03.45.40:077][395]LogTemp: Display: r = 0.000164
[2020.07.31-03.45.40:077][395]LogTemp: Display: force_between = 3710315776.000000
[2020.07.31-03.45.40:077][395]LogTemp: Display: acceleration_norm = 3710315776.000000
[2020.07.31-03.45.40:996][395]LogTemp: Display: x0, y0, z0 = -0.000076, 0.000139, 0.000044
[2020.07.31-03.45.40:997][395]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.40:997][395]LogTemp: Display: dx, dy, dz = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.40:997][395]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.40:997][395]LogTemp: Display: rsquared = 393900.187500
[2020.07.31-03.45.40:997][395]LogTemp: Display: r = 627.614685
[2020.07.31-03.45.40:997][395]LogTemp: Display: force_between = 0.000254
[2020.07.31-03.45.40:998][395]LogTemp: Display: acceleration_norm = 0.000254
[2020.07.31-03.45.41:810][395]LogTemp: Display: x0, y0, z0 = -0.000076, 0.000139, 0.000044
[2020.07.31-03.45.41:810][395]LogTemp: Display: x1, y1, z1 = 327382304.000000, -654764544.000000, -245536688.000000
[2020.07.31-03.45.41:811][395]LogTemp: Display: dx, dy, dz = 327382304.000000, -654764544.000000, -245536688.000000
[2020.07.31-03.45.41:811][395]LogTemp: Display: xh, yh, zh = 0.423999, -0.847998, -0.317999
[2020.07.31-03.45.41:811][395]LogTemp: Display: rsquared = 596184066760376320.000000
[2020.07.31-03.45.41:811][395]LogTemp: Display: r = 772129536.000000
[2020.07.31-03.45.41:812][395]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.41:812][395]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.42:486][396]LogTemp: Display: x0, y0, z0 = 327382304.000000, -654764544.000000, -245536688.000000
[2020.07.31-03.45.42:486][396]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.42:486][396]LogTemp: Display: dx, dy, dz = -327382304.000000, 654764544.000000, 245536688.000000
[2020.07.31-03.45.42:486][396]LogTemp: Display: xh, yh, zh = -0.423999, 0.847998, 0.317999
[2020.07.31-03.45.42:486][396]LogTemp: Display: rsquared = 596184066760376320.000000
[2020.07.31-03.45.42:486][396]LogTemp: Display: r = 772129536.000000
[2020.07.31-03.45.42:487][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.42:487][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.43:196][396]LogTemp: Display: x0, y0, z0 = 327382304.000000, -654764544.000000, -245536688.000000
[2020.07.31-03.45.43:196][396]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.43:197][396]LogTemp: Display: dx, dy, dz = -327382016.000000, 654764032.000000, 245536512.000000
[2020.07.31-03.45.43:197][396]LogTemp: Display: xh, yh, zh = -0.423999, 0.847998, 0.317999
[2020.07.31-03.45.43:197][396]LogTemp: Display: rsquared = 596183104687702016.000000
[2020.07.31-03.45.43:197][396]LogTemp: Display: r = 772128960.000000
[2020.07.31-03.45.43:197][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.43:197][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.43:759][396]LogTemp: Display: x0, y0, z0 = 327382304.000000, -654764544.000000, -245536688.000000
[2020.07.31-03.45.43:759][396]LogTemp: Display: x1, y1, z1 = -274306336.000000, 501318560.000000, 160800288.000000
[2020.07.31-03.45.43:759][396]LogTemp: Display: dx, dy, dz = -601688640.000000, 1156083072.000000, 406336960.000000
[2020.07.31-03.45.43:760][396]LogTemp: Display: xh, yh, zh = -0.440745, 0.846847, 0.297647
[2020.07.31-03.45.43:760][396]LogTemp: Display: rsquared = 1863666986400088064.000000
[2020.07.31-03.45.43:760][396]LogTemp: Display: r = 1365161856.000000
[2020.07.31-03.45.43:760][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.43:760][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.44:219][396]LogTemp: Display: x0, y0, z0 = -274306336.000000, 501318560.000000, 160800288.000000
[2020.07.31-03.45.44:219][396]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.44:220][396]LogTemp: Display: dx, dy, dz = 274306336.000000, -501318560.000000, -160800288.000000
[2020.07.31-03.45.44:220][396]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.44:220][396]LogTemp: Display: rsquared = 352420998852640768.000000
[2020.07.31-03.45.44:220][396]LogTemp: Display: r = 593650560.000000
[2020.07.31-03.45.44:220][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.44:220][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.44:629][396]LogTemp: Display: x0, y0, z0 = -274306336.000000, 501318560.000000, 160800288.000000
[2020.07.31-03.45.44:629][396]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000
[2020.07.31-03.45.44:630][396]LogTemp: Display: dx, dy, dz = 274306624.000000, -501319104.000000, -160800464.000000
[2020.07.31-03.45.44:630][396]LogTemp: Display: xh, yh, zh = 0.462067, -0.844467, -0.270867
[2020.07.31-03.45.44:630][396]LogTemp: Display: rsquared = 352421754766884864.000000
[2020.07.31-03.45.44:630][396]LogTemp: Display: r = 593651200.000000
[2020.07.31-03.45.44:630][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.44:630][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.44:988][396]LogTemp: Display: x0, y0, z0 = -274306336.000000, 501318560.000000, 160800288.000000
[2020.07.31-03.45.44:988][396]LogTemp: Display: x1, y1, z1 = 654764288.000000, -1309528576.000000, -491073216.000000
[2020.07.31-03.45.44:988][396]LogTemp: Display: dx, dy, dz = 929070592.000000, -1810847104.000000, -651873536.000000
[2020.07.31-03.45.44:988][396]LogTemp: Display: xh, yh, zh = 0.434730, -0.847331, -0.305024
[2020.07.31-03.45.44:989][396]LogTemp: Display: rsquared = 4567278393048956928.000000
[2020.07.31-03.45.44:989][396]LogTemp: Display: r = 2137119232.000000
[2020.07.31-03.45.44:989][396]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.44:989][396]LogTemp: Display: acceleration_norm = 0.000000
[2020.07.31-03.45.45:358][397]LogTemp: Display: x0, y0, z0 = 654764288.000000, -1309528576.000000, -491073216.000000
[2020.07.31-03.45.45:358][397]LogTemp: Display: x1, y1, z1 = 0.000000, 0.000000, 0.000000
[2020.07.31-03.45.45:358][397]LogTemp: Display: dx, dy, dz = -654764288.000000, 1309528576.000000, 491073216.000000
[2020.07.31-03.45.45:358][397]LogTemp: Display: xh, yh, zh = -0.423999, 0.847998, 0.317999
[2020.07.31-03.45.45:359][397]LogTemp: Display: rsquared = 2384734342896156672.000000
[2020.07.31-03.45.45:359][397]LogTemp: Display: r = 1544258560.000000
[2020.07.31-03.45.45:359][397]LogTemp: Display: force_between = 0.000000
[2020.07.31-03.45.45:359][397]LogTemp: Display: acceleration_norm = 0.000000


One of the planets just zooms off!

I think I may not understand how the tick function iterates through objects. There is one moment here



[2020.07.31-03.45.38:044][395]LogTemp: Display: x0, y0, z0 = 290.000061, -530.000122, -170.000046
[2020.07.31-03.45.38:044][395]LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000


Where the two objects are almost in the same place… Is it the same object somehow? I thought I caught that.

Before that they don’t move at all.



[2020.07.31-03.45.38:044][395]LogTemp: Display: x0, y0, z0 = 290.000061, -530.000122, -170.000046 [2020.07.31-03.45.38:044][395]
LogTemp: Display: x1, y1, z1 = 290.000000, -530.000000, -170.000000 [2020.07.31-03.45.38:045][395]
LogTemp: Display: dx, dy, dz = -0.000061, 0.000122, 0.000046 [2020.07.31-03.45.38:045][395]
LogTemp: Display: xh, yh, zh = -0.423999, 0.847998, 0.317999 [2020.07.31-03.45.38:045][395]
LogTemp: Display: rsquared = 0.000000 [2020.07.31-03.45.38:045][395]
LogTemp: Display: r = 0.000144 [2020.07.31-03.45.38:045][395]
LogTemp: Display: force_between = 4825805824.000000 [2020.07.31-03.45.38:045][395]
LogTemp: Display: acceleration_norm = 4825805824.000000

Tell me something…

What happens if you divide by zero?

Ok so I discovered that


for (TObjectIterator<APlanet> Itr; Itr; ++Itr) {

is returning duplicates of every object (which should be caught by


if (Itr->IsA(APlanet::StaticClass()))

but why is it doing that?) AND is returning objects I previously deleted.

Proof:

However only planets 3 and 5 exist.

So I think im getting divide by near zero because of either the duplication or because maybe there is an invisible deleted object in exactly the same place as the other one.

In my first post I already explain that I know that divide by zero is causing this, but that there is no evidence of two objects that are near the same position. This shows why that is the case, but idk why it is happening that these deleted objects exist and that objects are duplicated in the loop.