Space Engineers

Space Engineers

Subgrid Wheel Controller
52 Comments
Grebanton1234 27 Jun @ 11:48am 
Hey there, may I use your script for the current research bunker competition? I think legally I have to ask you for permission because I think by submitting the build I give Keen the right to use it how they want to.
Standard Squid 26 Oct, 2024 @ 1:27pm 
@Jack Schitt I am having the exact same problem. It was working perfectly last night then suddenly broke
kennet0508 5 Jul, 2024 @ 7:39am 
Another update:
The automatic parking brake seems to have happend because of mag plates autolock and set to use parking brake, removing that seems to have disabled the constant parking brake, so removing constys airplane parts fixed the error, and toggling off mag plate autolock fixed the automatic parking brake re-applying, but now i got a completely different issue, now it cant see the subgrid wheels, i think im gonna have to get back to this at a later stage in the build process
kennet0508 5 Jul, 2024 @ 5:53am 
Seems like maybe the modded wheels trigger the parking brake automatically?
kennet0508 5 Jul, 2024 @ 5:46am 
probably because he's suspension blocks have some greyed out options like steering and propulsion aswell as none of the wheel values can be modified, so somethings acting up
kennet0508 5 Jul, 2024 @ 5:44am 
ohh nwm, i think i know... its probably modded wheel blocks from consty's aircraft pack, weird that whiplash's script at the moment seems to work fine with it
kennet0508 5 Jul, 2024 @ 5:42am 
just got an error message:

Parked
Caught exception during execution of script:Object reference not set to an instance of an object.
at Program.WheelHandeler(IMyShipController cockpit, List`1 wheels)
at Program.Main(String argument, UpdateType updateSource)
at Sandbox.Game.Entities.Blocks.MyProgrammableBlock.<>c__DisplayClass42_0.<ExecuteCode>b__0(IMyGridProgram program)
at Sandbox.Game.Entities.Blocks.MyProgrammableBlock.RunSandboxedProgramActionCore(Action`1 action, String& response)

Any clue where i should start looking for cause?
Jack Schitt 10 Jun, 2024 @ 9:20am 
Checking Code fails.

"Program(116,64): Warning: Field 'Program.vel' is never assigned to, and will always have its default value 0"

Script won't run.
kennet0508 2 May, 2024 @ 6:54am 
Hey Tekk, Again it cant be said enough how impressive this script is, and the added banking feature is great.

I have another feature update request, its the same i asked last time but ive provided an example of why it would be beneficial. (now with the new tank framework API from Digi, creativity is flowing!)

- https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3237591926

The example has my current workaround for getting groups:
have the same script running on multiple programmable blocks with banking enabled, each one with a labeled group, example, programmable block 1, group 1, programmable block 2, group 2 etc.

feature update: Bank groups
Reason:
On custom suspension where you have layers of suspension, having one group of suspensions isnt enough.
suspension group 1 is strength, group 2 is angle, group 3 is wheels on ground. all three needs to move differently to achieve a good bank.
kennet0508 2 May, 2024 @ 6:54am 
Group 1 needs one neutral height while group 2 needs another while group 3 needs a third

Proposed setup/modification: (mind that im not good at coding but something ish like this?)

//Banking "rolls" the vehicle using suspension offset when turning
//The amount of banking is determined by how fast you are turning, modified by BankMod
bool SteeringBank = true; //Toggles banking the vehicle when turning to alleviate chance of rolling

//copy this part to add more groups:
string BankGroup = "Group 1";
double NeutralHeightOff = -1.5;
double MaxOffset = -0.5;
double MinOffset = -1.5;
double BankMod = -5.0;

//copy this part to add more groups:
string BankGroup = "Group 2";
double NeutralHeightOff = 0.55;
double MaxOffset = 1.3;
double MinOffset = 0.55;
double BankMod = -5.0;
Phooenix 12 Nov, 2023 @ 9:59am 
Yeah i think i modified the script so it did a similar thing
Tekk  [author] 12 Nov, 2023 @ 6:51am 
Rewrote how the script parks and brakes in general.
Instead of applying a force to all wheels based on the speed of the grid, it now applies it based on the rotational speed of each individual wheel.
Added some description to the three modifies for braking that should help fix individual issues.

This should fix the issue of wheels spinning when connected to other grids and parked, and should significantly improve parking brakes on an incline.

As for parking without wheels on the main grid;
You can add the PB to actionbar, and give it the argument "park", pushing this button will now toggle park on/off internally in the script, so it'll work with no wheels on the same grid as cockpit.

Have only tested it with two mid-sized grids, so probably some bugs to iron out, feedback is appreciated :)
Phooenix 12 Nov, 2023 @ 3:39am 
Yeah i got it to work but can't remember how xD (the cockpit was on a large piston and a hinge, lowered to allow entrance and goes up and out to give better view)
kennet0508 11 Nov, 2023 @ 5:54pm 
@Phoenix, parking brake only works if theres a wheel suspension on the same grid as you cockpit and both that suspension and the cockpit needs to have parking brake enabled.
@waddles, i would probably group and turn wheels on/off with a button if parking brake doesnt fix it
Waddles 19 May, 2023 @ 11:10am 
whenever my rover is hooked up to a connector to charge the wheels spin on their own, is there a fix for this? it seems to be connected to the brake prop override
Phooenix 9 May, 2023 @ 9:10am 
Hmm okey now today it worked, wierd. However the parking brake doesn't work, not even a little like in description, will look around and see if i can fix it. :)
Phooenix 9 May, 2023 @ 8:34am 
Tekk, that's what i was doing. I only have one controller, maybe i was explaining badly. I meant that I tried both changing the name manually and also allowing it to default to the first it founds ( the only one) and it didn't work any time. And i did try both of these solutions for each of the control seat, cockpit and industrial cockpit.
Tekk  [author] 8 May, 2023 @ 12:18pm 
It should work with all controllers; It sounds like you haven't changed the "Controller_Name" in the script and it's defaulting to the first it finds, if you have more than one on your craft, that may not be the one you're intending. Keep in mind all seats/cockpits/remotes count as ship controllers.
Phooenix 7 May, 2023 @ 6:55pm 
Doesn't seem to work, tried both with cockpit and control seat and industrial cockpit, it compiled fine but said "found no cockpit, using control seat instead" and the same for the others, then i tried manually changing the name to the different cockpits, it compiled fine but didn't work. The cockpit/control seat is on a sub sub subobject, (a hinge connected to a piston connected to a hinge that's connected to the control object, It shouldn't matter because it can still find it but i thought i should mention it anyways.
kennet0508 14 Feb, 2023 @ 3:37pm 
Wow, this is some next level mind blowing stuff!
after initial testing there are a couple of thing to point out:

- Sometimes turning doesnt trigger enough roll to give "enough" banking", this seems to be caued by counterforces from high weight/speed when turning, this is also observed if the wheels loose ground contact and looses its turn momentun. this resets the banking angle adding to the external force, which is scary in a tight turn.

- Banking engages after the rover starts turning and wheels in SE takes time from button press before engaging into a turn (amplified at higher speeds), it feels like the roll engages late and isnt "tight" when needed

Would there be a way for button inputs to engage roll faster?
Example: If player press button "D", script initiates player driven max banking, Player releases D, script reverts to calculating y axis roll? (the way the script already works, it keeps the bank for the remainder of the turn after release and reverts smoothly)
kennet0508 14 Feb, 2023 @ 2:35pm 
yeah. i tried setting it higher, anything above 25 = twitching if strength is set high
Tekk  [author] 14 Feb, 2023 @ 2:06pm 
1: Done.
2: Considered it, felt it got too convoluted.
Banking is done by how fast the vehicle rotates around it's own Y-axis, in Radians/sec.
eg. if you rotate 90 degrees in one second, you're rotating at a rate of +pi/4 radians per second.
That's roughly 0.79, making a BankMod=5 give you an offset of around +3.9 (or whatever your upper limit is. Turning 90 degrees in 10 seconds would give you +0.39 offset

Felt it easier to leave it as a "If it's not banking enough, raise it" sort of value :p
kennet0508 14 Feb, 2023 @ 1:33pm 
This is so far pretty damn Epic!

two things:
1, is there a way to make it groupable? example: only wheel suspensions in group "banking" is applied
Reasoning is that i use a lot off weird suspension tricks, like having large grid 1x1 as springs and 5x5 small wheels on hinges, in that case i would only want the 1x1 spring system to bank the rover, not the small grid 5x5 wheel as they would only serve to lower ground clearance risking voxel collsion

2. add the min/max values in the readme section, BankMod 5 doesnt give much information, does it go to 10? 100? 1000? 1000000?
example:
double BankMod = 5; //Modifies how strong the banks is.(0<->100, default = 5)
Strong Hoov ✅ 13 Feb, 2023 @ 11:53am 
Nice!!
kennet0508 13 Feb, 2023 @ 11:50am 
Cant wait, imma test it out asap!
Tekk  [author] 13 Feb, 2023 @ 10:08am 
Cool idea, it is done. (dunno how fast steam updates)

Added a twist tho; the amount of banking is dependent on how fast the vehicle is turning, instead of a static amount for any turn, I think that makes sense, and it looks cool when driving slalom!

For now, the settings for it is at the top of the script with the others, having added the following:
SteeringBank - Set to true, to enable banking. (false by default)
NeutralHeightOff - The susp. offset you want in neutral position (0 by default)
MaxOffset - The max susp. offset you want (1.3 by default)
MinOffset - The min susp. offset you want (-1.5 by default)
BankMod - Modifier for the banking action, eg. higher values make it bank more at lower speed. (5 by default)

Ran some tests but may have missed something, so feedback would be nice.

If it's not how you imagined or you have an idea of a better way for it to behave, do tell :)
kennet0508 12 Feb, 2023 @ 11:03pm 
Hey Tekk

I have a feature whish for your script.
(Picture for relevance - https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2930053454)

Would you be willing to ammend/add a function, that would allow the suspension to bank into turns? a type of "Active Body Control" or anti roll? (or perhaps have it as a function in a separate script?)

A function, that when you steer left or right (A/D) the wheel suspension height offset is altered to offset potential roll to custom amount

It would be ofc be off by default, and could be enabled in custom data to maintain the simplicity of your script as is.

Im not a coder so i wouldnt even know where to start, i havent seen anyone make something like this, and this is something im really missing from a lot of my builds. and perhaps for many others
Tekk  [author] 29 Apr, 2022 @ 1:54pm 
Sure, you can do that :)
It will only consume power when standing still, when park/handbrake is actually enabled.
If you used a piston + gear instead, you could just avoid putting the vehicle in park, and the motors wouldn't consume power.
fenlander 29 Apr, 2022 @ 1:50pm 
To park the vehicle without consuming power can you put a landing gear on a piston? Once extended switch off the piston. The gear doesn't need power.
Tekk  [author] 14 Apr, 2022 @ 7:09pm 
OBS: Also fixed the inverted steering, and added a toggle at the top of the script to invert steering if wanted.
Tekk  [author] 14 Apr, 2022 @ 6:59pm 
Hey people, just did a bit of an overhaul on the script:

- Improved how the script recognizes the center of the craft, so wheels should now be turning in the right direction, even if the controller is not at the center of the craft!

- The script now registers "parking" and will brake accordingly, additionally the script can be run with the argument Park to toggle an internal parking brake on/off, in case the game won't let you use parking or handbrake.

- Changed how the parking brake works, it's not perfect, but it should work a lot better now (Check description for the relevant info if you want to modify braking behavior)

- Realized that a script can set Propulsion Override (way) beyond 100%, so you are now able to set how much propulsion is applied through the variable PowerMod .

- The script will now tell you if your desired cockpit/seat/remote was not found and that another one has been chosen, along with which has been chosen.
Tekk  [author] 21 Mar, 2022 @ 4:40pm 
Either I am missing something, or keen isn't prioritizing keeping scripting up to date with features.

I don't know of a way to access Parking, I can only "see" handbrake, so that's the only one the script reacts to :/
Juntao 21 Mar, 2022 @ 4:36pm 
great script, but does anyone know how to add wheel parking brakes?
Turret problems 12 Jul, 2021 @ 4:13pm 
Excellent, thank you!
:DS2_Marker: :selike:
Tekk  [author] 12 Jul, 2021 @ 12:53pm 
@Turret Problems
Go for it :)
Turret problems 12 Jul, 2021 @ 8:05am 
Ive made a modification for this script to allow a reference direction, in case you are driving from a manned turret for example, Could I have permission to upload it and link back to this one? it also includes the steering fix
Spice 8 Apr, 2021 @ 4:37am 
Easy inverted steering fix for this script "turner = cockpit.MoveIndicator.X;" becomes "turner = cockpit.MoveIndicator.X * -1;" just invert X and you are fine. Great script. Good for a 27k ton planet-hauler.
ramphaleom 25 Sep, 2020 @ 10:16pm 
super scripts . nice script :steamhappy:, Merci bcp :)
dlouhynohyzadnejmidget 29 Aug, 2020 @ 4:44am 
how do i paste the script into the pb? i mean where is the script, and wherre do i put it in?
Mr.Pig 24 Aug, 2020 @ 5:52pm 
ill have to take a look.
Tekk  [author] 24 Aug, 2020 @ 5:18am 
@Gunnerman4581
Is handbrake on by any chance?
There doesn't seem to be a way to braking to the wheels using script, so i'm doing it using power instead.

@Rabenschild
I can add that, assuming the ownership works atm
Mr.Pig 20 Aug, 2020 @ 4:24pm 
im having a problem where the script is taking over propulsion and keeps increasing it to -0.2 or higher. anyone know how to fix this?
Rabenschild 25 Apr, 2020 @ 7:11am 
I know you are having trouble with the ownership of the script, but is there a way to make it so the script only takes specific wheels or that you can exclude wheels? I am running into the problem that some wheels i do not want to be moving are reacting to the script.
keyofrage yt 11 Feb, 2020 @ 5:14am 
kk thx
Tekk  [author] 10 Feb, 2020 @ 1:03pm 
Right.. So, i've somehow lost ownership of the script, i guess? I am not allowed to replace or publish, and my script has in my game been split into a local version (which won't publish) and a workshop version (where i can't do either)...So i guess i'm not updating this one.

**TO FIX INVERTED STEERING**

Look for:
"if (relPos.Z < 0) { turner = -turner; }"
at the bottom of the script and change it to
"if (relPos.Z > 0) { turner = -turner; }"

Just flip the "<"

That should fix it
keyofrage yt 10 Feb, 2020 @ 12:37pm 
i tried that but the rotors stoped moving alltogether
Tekk  [author] 10 Feb, 2020 @ 11:59am 
Great!
Personally i limit the rotors to +/- 45 degrees, usually prevents then from gettint too close to vertical and still allows for enough rotation to not be an issue while driving.
maybe reduce wheel power as well.

I've tought about putting a torsion spring kinda deal in to make the rotor go towards a neutral position, but fear it may cause issues in some use cases.
keyofrage yt 10 Feb, 2020 @ 11:34am 
thx any way
allso how do i prevent the rotor from fliping over cause i had it like 2 rotors on each side with 2 wheels each and for some reason while moveing they have a high chance of fliping is it to do with the weight
keyofrage yt 10 Feb, 2020 @ 11:32am 
i realised that about a hour after and i feel like a moron
Tekk  [author] 10 Feb, 2020 @ 11:09am 
It's inverted because i had my wheels upside-down when i was testing it :p

For now, tick off "invert steering" on the wheels, gonna upload a fixed version within the hour