My Summer Car
Недостатньо оцінок
Better Keyboard Throttle and Brake (optional mouse steering)
Автор: Randox
A script for freePIE to convert keyboard throttle and break input into smoother joystick output with variable operation via vJoy. Optional mouse steering code included.
   
Нагородити
До улюбленого
В улюблених
Прибрати
Introduction
This script is something I modified to add mouse steering to My Summer Car. The mouse steering works, but I've decided to stick with the games built in keyboard steering for now, or use my phone as a controller.

However, I did have the idea for some better throttle and brake controls. The system I've come up with provides 3 different maximum (what you'll get holding the button down) throttle values, 2 values for braking, and two different attack and release speeds through the use of two toggle buttons.

It should be noted that I use a Logitech g600 mouse, which has plenty of side buttons, and I made this script with that in mind. If your mouse can map at least 2 keyboard buttons (or you have two extra buttons and can figure out how to poll them directly), this should work for you pretty much as is. For users of standard mice, you'll need to find keybindings that work for you.

This guide is almost certainly longer than it needs to be, but I like documentation, and I want to make this as easy for people to figure out as possible. I've tried to order things by order of importance.
Programs You Need
You'll need a couple programs to make this work; both free.

The first program you need is called vJoy. This program will create the virtual joystick that we'll be using as input for My Summer Car. You can read about it and find a download link here[vjoystick.sourceforge.net].

To make vJoy do anything for us however we need a feeder, a program that tells vJoy what to do. For that we will use a program called freePIE. You can read about it and find a download link here[andersmalmgren.github.io].

Note that when installing vjoy you'll want to install all 3 utilities (monitor, confiure, and feeder). You'll also need to configure vJoy by launching the configuration utility and setting up like this:

With vJoy properly configured, you can open freePIE, go to file>new and paste your desired script into the text editor window that has opened. To run the program, select "script" from the bar at the top and then "Run Script". To stop, go to "script" again and then select "Stop Script".

You can also use F5 and Shift+F5 respectively if you have focus on the freePIE appication. The shortcut wont work from inside the game or while focused on other windows (to focus simply click anywhere on freePIE).
Script
The script is too long to fit in a guide, so I've uploaded it instead. You can find all versions of the script here: https://github.com/Round-Beagle/MSC-freePIE-Sctipt

There are currently 2 versions of the script. They contain identical code, however one of them has the code for mouse steering enabled by default. I've also included a duplicate of the version that does not have mouse steering enabled, saved as a normal .txt file instead, for those who don't trust the .py Python extension. Notepad can open any of the files. If you use the text version, you'll need to copy the script from notepad into freePIE (freePIE can open the python versions directly).
Script Features
Joystick Mapping: This script maps the accelerator and brake keys to a single joystick axis; the Y axis. The throttle uses the positive Y axis, and brake uses the negative.

Attack and Release Time: This is the basic functionality of the script. Rather than have the throttle and brakes instantly jump from 0% to 100% all the time, it will now take a fraction of a second for the throttle/brakes to smoothly ramp up to 100% when you hit the gas/brake key. A similar delay in returning to zero is applied when you release the key.If you switch from gas to brake or vice versa before the joystick has naturally reached zero (where it applies neither throttle nor brake), the joystick will instantly jump to zero and progress from there. Holding both keys down at once will apply throttle.

Cruising (Secondary) Mode: This mode is toggled on and off with the Secondary key (default T). Secondary mode limits how far the virtual joystick can move in either direction. This may be desirable when trying to cruise at a certain speed, or when you you don't want to slam on the brakes all the way. Be aware that stopping distance is dramatically longer when this mode is on, and I highly recommend leaving the Space Bar enabled as a second reset button to quickly turn secondary mode off (you wont want partial throttle after a power slide anyway).

Hold Mode: This mode is toggled on and off with the Hold key (default Y). This mode alters the attack and release time to be longer. This is intended to facilitate tap throttle/brakes by causing the joystick to hold a more constant position. This mode may cause input to feel laggy, especially if you use it while accelerating. This mode, along with Secondary mode can be disabled with the reset key (default U), or the space bar (if enabled).

Low Mode: This is an extra reduction in the maximum throttle (and only the throttle. Braking intensity stays the same as Secondary mode). This is enabled by default, but can be easily turned off. When enabled, the secondary key will cycle through this extra mode only when hold mode is on.

Look at the watch tab at the bottom of freePIE while the script is running to see the toggle states for low, hold, and secondary. The value of the throttle/brake axis is also displayed here.

Optional - Mouse Steering: I've included code for those who wish to have mouse steering. One version of the script has it enabled by default, the other has the relevant code inside comments. Mouse steering comes with two extra key bindings. Scrolling up on the mouse wheel will instantly centre the steering, while holding down the B key will pause the steering. The original idea was to use the DPI switch on my mouse. When driving, I would use a lower sensitivity to keep the camera relatively still, but could pause the steering and switch to high sensitivity to look around. You also wish to just set mouse sensitivity to zero when driving.
Modification and Mouse Steering
The script is written in Python, one of the more easily read programming languages. The script itself provides enough examples on how the language works that many people will probably find they can make alterations and additions without too much hassle. The error checker built into freePIE is a bit obtuse though; you might want to google for an online syntax checker if you get errors that have no corresponding line.

I've also included the code for mouse steering. There are 3 sections of code that need to be uncommented, plus another line at the bottom for diagnostic output. They shouldn't be too hard to find. They're all under Mouse or Steering headings, and I've put them in triple " marks (I've also put actual comments inside those marks, so don't uncomment anything that isn't actually code).

Alternately, I've included a third file that comes with mouse steering enabled by default.
Setting Axis
There are two ways to do this.

If you enable mouse steering, that's easy. Go into the car controls in game, select the control and move the mouse.

Throttle and brake are different though. The game will detect both the virtual joystick and the actual key press, and it will choose the key press, which is not what you want. You have two options.

When you launch the game you get a settings window with two tabs. Switch to the controls tab and set the axis here. To avoid having the same problem, you need to open up the program vJoy Feeder that comes with vJoy and use that. Set the y axis to 50 in the feeder program, then switch to the settings window for MSC and click on the axis you want to set, then switch back into the feeder and move the Y axis slider up (for throttle) or down (for brake).

Alternately, change the throttle_decrease_time in the script (line 91) to something like 800 or 2000 and then run it. Launch my summer car and go into the car controls menu. Hold down the throttle or brake button (whichever you want to set), release it, and quickly click on the axis you want to bind. The axis will still be moving back towards zero which the game will detect. MSC doesn't mind being alt-tabbed, so you can tab out, pause the script, set the throttle_decrease value back and run the script again, and away you go.
Коментарів: 24
kuni 24 квіт. 2024 о 13:04 
can i use your script in assetto corsa?
önepamöp 1 січ. 2022 о 12:30 
omg. thanks. it worked !!!!!!!!!!
Randox  [автор] 1 січ. 2022 о 12:12 
This is the format that racing wheel pedals (G27, T150, etc) normally use. If you tell the game you have a wheel instead of a controller it should work fine. However, it's also easy enough to adjust. To have both axis reduce only to 0 and not go negative you only need to edit lines 101 and 127. Line 101 should be changed to:
throttle_min = 0

And line 127 should be changed to:
brake_min = 0

Just delete the int32_min from both of these lines inside FreePie and put a 0 in instead and save it, and it'll work properly for games expecting a zero to + input.
önepamöp 1 січ. 2022 о 8:55 
Many thanks! But this is not quite what you need. pedal axes now go back to "original default" (-16382). It is necessary to make sure that the axes work only in (plus +) from 0 to 16382. without a minus.
Randox  [автор] 1 січ. 2022 о 8:03 
Done. IndependantThrottlesWithSteering. This is actually how the original Skagen version of the script worked (except I've kept all the extra stuff I added in). Steering was disabled in the other script because I used the version with steering commented out (the code is there, but behind comment tags to prevent it from running). I've left the steering code active in this one. This one I actually did test using vJoy Monitor. It seems to work fine, though I might up the sensativity values a bit more for racing. Lines 92 and 93 for throttle 121 and 122 for brakes.
önepamöp 31 груд. 2021 о 22:46 
Sorry, but that's not quite right. I guess I want too much from that script or you. I wanted the throttle and brake axles to work independently of each other and not interrupt each other, now it works like this - (if I press the throttle, then I cannot press the brake at the same time). By the way, why is the axis for the mouse (v.x) not working now?
Randox  [автор] 31 груд. 2021 о 17:40 
@V.Barmin It's doable. The script actually does include a third axis (v.z) that isn't used. I think I had originally planned on it being two axis (I have a third unused axis and an unused variable in the script), but it was simpler for a couple reasons not to. My character limits are very limited here or I'd actually write out the changes that need to be made. Instead, I've just gone ahead and uploaded a modified script to GitHub with the changes applied. Basically, I'm just taking the existing throttle that uses min to 0 for brake and 0 to max for gas and mapping that onto two axis that both range from min to max, which is why all the throttle values are multiplied by 2.

I hope this helps.
önepamöp 31 груд. 2021 о 2:53 
Hello again. How can I make the gas pedal and the brake pedal on different axles? is it even possible? you have gas and brake on the same axis in the script.
Randox  [автор] 30 верес. 2020 о 4:12 
Thanks for passing it along. I'll take a look and see if it's something I can incorporate.
önepamöp 28 верес. 2020 о 11:16 
i ran "mouse_joy_offscreen" script. there is up and down virtually. put the gas and brake on it. then ran your script and it works like W S