Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class NSPlanetActor extends actor
- placeable;
- var const editconst DynamicLightEnvironmentComponent LightEnvironment;
- var const StaticMeshComponent Planet;
- var() Actor OrbitActor;
- var() int degrees;
- var() float Radius;
- var() float Speed;
- var float angle;
- var float circumference;//added this
- var vector Loc;
- var int ticks;
- simulated function PostBeginPlay()
- {
- super.PostBeginPlay();
- enable('tick');
- Loc.X = Radius * cos(angle);
- Loc.Y = Radius * sin(angle);
- Loc.X += OrbitActor.Location.X;
- Loc.Y += OrbitActor.Location.Y;
- SetLocation(Loc);
- }
- event Tick(float DeltaTime)
- {
- local Vector Delta;
- //angle = degrees * (PI/(Radius/Speed));
- //degrees += 1;
- //this function is taking radius divided by speed, this results in no useful data
- //you want to get the circumference of the path its going to be orbiting, this way you have the total distance it will be travelling and you can than figure out the angle needed to make it move that distance
- //Get circumference of circle, you can calculate this once and store it as it doesnt change
- //idk much about uscript so figure out where to put this so it calculates once
- circumference = 2 * Radius * PI;
- //same with this angle, it needs to be calculated once, if you dont need to use circumference again you might as well just make it a temporary variable and store angle instead
- angle = PI / (Speed / circumference);
- //the way the angle is calculated is simple because our circumference is a factor of PI, so if our speed is 1 and our circumference is 4 : 1/4 = 0.25, 0.25 * PI = PI/4 = 90 degrees
- //Therefore, for it to travel 1 unit for a circle with radius 4 it will move 90 degrees
- ticks++;
- Loc.X = Radius * cos(ticks * angle);//ticks * angle, every tick it will move the angle, you could have this related to delta time instead as i think each tick is about 30 milliseconds, depends on how fast unreal's physics updates
- Loc.Y = Radius * sin(ticks * angle);
- Loc.X += OrbitActor.Location.X;
- Loc.Y += OrbitActor.Location.Y;
- Delta = Loc - self.Location;
- Move(Delta);
- }
- /*
- auto state idle
- {
- Begin:
- }
- */
- DefaultProperties
- {
- //Setting up the light environment
- Begin Object class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
- bEnabled = true;
- End object
- LightEnvironment = MyLightEnvironment;
- Components.add(MyLightEnvironment);
- //Setting up the mesh
- Begin Object class=StaticMeshComponent Name=BaseMesh
- StaticMesh=StaticMesh'NS-Planets.Models.Planet'
- LightEnvironment=MyLightEnvironment
- MotionBlurScale=0.00
- end object
- Components.Add(BaseMesh)
- CollisionComponent=BaseMesh
- bCollideActors=true
- bBlockActors=true
- Radius=10000
- Speed=2 // Planetspeed in Editor should be set to 0-1 app.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement