Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Class NSPlanetActor extends actor
  2.         placeable;
  3.    
  4. var const editconst DynamicLightEnvironmentComponent LightEnvironment;
  5. var const StaticMeshComponent Planet;
  6. var() Actor OrbitActor;
  7. var() int degrees;
  8. var() float Radius;
  9. var() float Speed;
  10. var float angle;
  11. var float circumference;//added this
  12. var vector Loc;
  13. var int ticks;
  14.  
  15. simulated function PostBeginPlay()
  16. {
  17.         super.PostBeginPlay();
  18.         enable('tick');
  19.  
  20.         Loc.X = Radius * cos(angle);
  21.         Loc.Y = Radius * sin(angle);
  22.    
  23.         Loc.X += OrbitActor.Location.X;
  24.         Loc.Y += OrbitActor.Location.Y;
  25.  
  26.         SetLocation(Loc);
  27. }
  28.  
  29. event Tick(float DeltaTime)
  30. {
  31.         local Vector Delta;
  32.  
  33.         //angle = degrees * (PI/(Radius/Speed));
  34.     //degrees += 1;
  35. //this function is taking radius divided by speed, this results in no useful data
  36.     //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
  37.  
  38.     //Get circumference of circle, you can calculate this once and store it as it doesnt change
  39.     //idk much about uscript so figure out where to put this so it calculates once
  40.     circumference = 2 * Radius * PI;
  41.    
  42.     //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
  43.     angle = PI / (Speed / circumference);
  44.     //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
  45.     //Therefore, for it to travel 1 unit for a circle with radius 4 it will move 90 degrees
  46.  
  47.        
  48.     ticks++;
  49.    
  50.         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
  51.         Loc.Y = Radius * sin(ticks * angle);
  52.    
  53.         Loc.X += OrbitActor.Location.X;
  54.         Loc.Y += OrbitActor.Location.Y;
  55.  
  56.         Delta = Loc - self.Location;
  57.  
  58.         Move(Delta);
  59. }
  60.  
  61. /*
  62. auto state idle
  63. {
  64.         Begin:
  65. }
  66. */
  67.  
  68. DefaultProperties
  69. {
  70.         //Setting up the light environment
  71.         Begin Object class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
  72.                 bEnabled = true;
  73.         End object
  74.         LightEnvironment = MyLightEnvironment;
  75.         Components.add(MyLightEnvironment);
  76.  
  77.         //Setting up the mesh
  78.         Begin Object class=StaticMeshComponent Name=BaseMesh
  79.                 StaticMesh=StaticMesh'NS-Planets.Models.Planet'
  80.                 LightEnvironment=MyLightEnvironment
  81.                 MotionBlurScale=0.00
  82.         end object
  83.  
  84.         Components.Add(BaseMesh)
  85.         CollisionComponent=BaseMesh
  86.         bCollideActors=true
  87.         bBlockActors=true
  88.  
  89.         Radius=10000
  90.         Speed=2                // Planetspeed in Editor should be set to 0-1 app.
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement