Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cockpit rotational input to piston movement //
- // This is the name your reference ship controller / cockpit has to end with
- // i.e. "Cockpit - Reference", "Remote Control - Reference" etc.
- const string controllerName = "- Reference";
- // The desired movement speed in m/s
- const float movementSpeed = 3f;
- // The desired return speed multiplier
- // It gets multiplied with the movementSpeed so that -0.5f return speed and 5 m/s movementSpeed become -2.5 m/s return speed
- const float returnMultiplier = -0.5f;
- // The names that the pistons have to end with
- // i.e. "Piston +x", "Piston -z"
- string[] pistonNames = new string[]{"+x", "-x", "+y", "-y", "+z", "-z"};
- // Set this value higher than 0f if you want to have a standard velocity for all inputs
- // Note that this should match your return multiplier if you want your extract speed to match the retract speed
- const float standardVelocity = 0f;
- // DONT CHANGE BELOW
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- IMyShipController controller;
- Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update1;
- }
- public void Main(string arg)
- {
- if(controller == null || !controller.IsFunctional)
- {
- GridTerminalSystem.GetBlocksOfType<IMyShipController>(blocks, x => x.IsFunctional || x.CustomName.EndsWith(controllerName));
- if(blocks.Count < 1)
- {
- Echo("No ship controller found\nTerminating");
- return;
- }
- controller = blocks[0] as IMyShipController;
- }
- GridTerminalSystem.GetBlocksOfType<IMyPistonBase>(blocks);
- Echo($"{blocks.Count} Pistons found");
- foreach(IMyTerminalBlock block in blocks)
- {
- for(int i = 0; i < pistonNames.Length; i++)
- {
- if(!block.CustomName.EndsWith(pistonNames[i]))
- continue;
- IMyPistonBase piston = block as IMyPistonBase;
- switch(i)
- {
- case 0:
- if(controller.RotationIndicator.X > 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : controller.RotationIndicator.X);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- case 1:
- if(controller.RotationIndicator.X < 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : -controller.RotationIndicator.X);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- case 2:
- if(controller.RotationIndicator.Y > 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : controller.RotationIndicator.Y);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- case 3:
- if(controller.RotationIndicator.Y < 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : -controller.RotationIndicator.Y);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- case 4:
- if(controller.RollIndicator > 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : controller.RollIndicator);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- case 5:
- if(controller.RollIndicator < 0)
- piston.Velocity = movementSpeed * (standardVelocity > 0f ? standardVelocity : -controller.RollIndicator);
- else
- piston.Velocity = movementSpeed * returnMultiplier;
- break;
- default:
- break;
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement