Axis Mixing - Solved
-
- One Eyed Hopeful
- Posts: 14
- Joined: Fri Oct 11, 2013 7:01 pm
Axis Mixing - Solved
I'm hoping to create a script that combines axes, such that movement on one physical axis causes two virtual axes to move in the same direction, and movement on another physical axis causes the same two virtual axes to move opposite each other. Both operations would have to work without interfering with one another such that the result is additive (think tank controls). Is this possible, and if so, how might I go about doing it?
Last edited by Billhelm on Fri Aug 28, 2015 11:34 am, edited 1 time in total.
-
- One Eyed Hopeful
- Posts: 19
- Joined: Mon Jun 15, 2015 10:30 am
Re: Axis Mixing
It certainly is possible, but it is true that multiple writes to a field is a deceptively tricky thing to do.
You said you wanted something like tank controls, an additive combination of both inputs. I assume then you have two outputs that behave like levers on a WWII tank or the pedals on an excavator. Each controls one side of the drive train, so steering is done by differential drive.
This isn't a particularly complicated scenario, say you have the following setup:
So, you'd have to do something like this:
That's about all there is to it. Note that the result is clamped between -1 and 1. This is important to avoid going into 'overdrive' if both inputs are being applied at the same time. (think full fwd drive while steering). The clamp will cause the side already driving to just keep driving, and the other side will slow down.
Also note that I assumed that values <0 in diffDrive mean you are applying left input. Change those + and - signs as needed.
This is all pseudocode, ofc, but the rest of it depends on your setup, so that's about as much help as I can offer.
Hope this helps!
Cheers
You said you wanted something like tank controls, an additive combination of both inputs. I assume then you have two outputs that behave like levers on a WWII tank or the pedals on an excavator. Each controls one side of the drive train, so steering is done by differential drive.
This isn't a particularly complicated scenario, say you have the following setup:
Code: Select all
inputX = your physical x axis
inputY = your physical y axis
axisLeft = the virtual output for left side drive
axisRight = well you get the idea...
Code: Select all
// renaming here is redundant, but makes it easier to understand (hopefully)
diffDrive = inputX
linearDrive = inputY
axisLeft = max(min(linearDrive - diffDrive, 1), -1)
axisRight = max(min(linearDrive + diffDrive, 1) -1)
That's about all there is to it. Note that the result is clamped between -1 and 1. This is important to avoid going into 'overdrive' if both inputs are being applied at the same time. (think full fwd drive while steering). The clamp will cause the side already driving to just keep driving, and the other side will slow down.
Also note that I assumed that values <0 in diffDrive mean you are applying left input. Change those + and - signs as needed.
This is all pseudocode, ofc, but the rest of it depends on your setup, so that's about as much help as I can offer.
Hope this helps!
Cheers
-
- One Eyed Hopeful
- Posts: 14
- Joined: Fri Oct 11, 2013 7:01 pm
Re: Axis Mixing
Thank you very much! That's exactly it. For anyone else, here is the exact code that I used:
Code: Select all
inputX = joystick[1].x
inputY = joystick[1].y
diffDrive = inputX
linearDrive = inputY
axisLeft = max(min(linearDrive - diffDrive, 1024), -1024)
axisRight = max(min(linearDrive + diffDrive, 1024), -1024)
vJoy[0].x = axisLeft
vJoy[0].y = axisRight