This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Dave-ee Jones's profile picture

Dash - L2drive a manual car!

Started by Dave-ee Jones, 25 August 2017 - 12:12 AM
Dave-ee Jones #1
Posted 25 August 2017 - 02:12 AM
DASH
Dave-ee's Dash (as in car dash..)




Have you ever wanted to learn how to drive a manual in ComputerCraft? (pretend that you have)
Well, this should do the trick. I haven't implemented a speedometer / speed in general but most other mechanics (ha, a pun..) of a car's transmission and engine are implemented. Basically you can change gears, rev the car up nice and good, oh, and don't forget to start the car first. YES, it is possible to stall the car..(l2use clutch peeps..).

How does it work?
Well, you can start the car by holding down the clutch (default key: Left Ctrl) and then clicking and holding on the ignition for 1 second (the ignition is the little box on the left of the gearstick, has a "key" in it). Once that is green you can go into first gear by pressing the Up Arrow, because you are, by default, in Neutral. The Up Arrow and Down Arrow change gears, up and down respectively. You can go back to neutral, or even reverse, by using the default keys N and M respectively (N for neutral, M for reverse).

The accelerator's key is, by default Right Alt and the brake's key is, by default, Space.

I keep stalling it!
Yep. Keep in mind that you need to give it some rev before you "dump the clutch" (let the clutch out - release Left Ctrl), otherwise you will stall the car. Also keep in mind that if your RPMs are too low (below 500) when in a gear higher than 3, you will stall as you don't have enough revs to keep your gear. Also, make sure you put the clutch in before and during you changing gears.

What in the world were you thinking when you coded *such-and-such*?
Keep in mind I'm not a car-mechanic expert, I don't claim to know everything about transmissions, gear-ratios and car control in general. This is just a few basic calculations for the simple-learning.

I also have yet to fix the rev-changing when you gear change. In a real manual if you go up a gear your RPMs go down, if you go down a gear the RPMs go up. This isn't exactly implemented yet (it kind of is but it isn't accurate).

Will you implement speed?
Eventually, probably, but it's far more difficult than a tachometer because it means many more ways of stalling, gear changing and, maybe, even rev matching!

I noticed you have the TRANSMISSION variable, does this mean you are going to add an Automatic feature?
Yep, probably. It just means it will automatically enable the clutch and change gears when it needs to. You will still be able to override to neutral/reverse using the normal method.

There's just..something..missing..It doesn't feel right..
I KNOW! NO SOUND!! UGHHHHHH! Driving me crazy!

Can I use this as background code for a car game I want to make?
Sure. No need to ask. I would love to be in the credits but it's not required.

Can there be like a "Great shift!", "Too much rev!", "Woah, gear is way too high for this speed!"?
Well, maybe. It would be a good idea, make it more interactive and intuitive, but not right now. Maybe later.

No pics, no cli-
http://imgur.com/a/PcbLS




Pastebin:

pastebin get DGcyaue7 dash


PLEASE give suggestions and feedback because I know there is a lot that needs to be done to make this complete!
Edited on 31 August 2017 - 05:12 AM
Saldor010 #2
Posted 25 August 2017 - 02:24 AM
Looks very interesting! I'll have to try it out when I get a chance.
Exerro #3
Posted 25 August 2017 - 11:18 AM
There's just..something..missing..It doesn't feel right..
I KNOW! NO SOUND!! UGHHHHHH! Driving me crazy!

Heh, I see what you did there.

Interesting idea though. I've never thought of making a real-world education program inside CC. I wonder what drivers would think of this, whether it's realistic or not.
SquidDev #4
Posted 25 August 2017 - 11:45 AM
I wonder what drivers would think of this, whether it's realistic or not.
Something which immediately sticks out is that you can't control how far down the clutch is, so it can't sit at the "biting point". None the less, it's a pretty cool program. Now we need a way to rig up some gaming pedals :P/>.
Lupus590 #5
Posted 25 August 2017 - 12:07 PM
Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?
The Crazy Phoenix #6
Posted 25 August 2017 - 06:06 PM
Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?

That solution would require a mod that adds a block that outputs a redstone signal between 0 and 15 based on the position of the analog input.
Redstone should have enough resolution to avoid stalling, but it wouldn't be smooth.
Dave-ee Jones #7
Posted 26 August 2017 - 01:10 AM
I wonder what drivers would think of this, whether it's realistic or not.
Something which immediately sticks out is that you can't control how far down the clutch is, so it can't sit at the "biting point". None the less, it's a pretty cool program. Now we need a way to rig up some gaming pedals :P/>.

Yep, that's the thing. Unfortunately the only way I could fix that is utilise the mouse and use a dragging feature or something.

I was actually looking at my racing pedals in the other corner while making this going "sorry, you can't help me with this one :(/>". If only..

Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?

Oo that would be interesting..I kinda wanted to use the gearstick for dragging as well, like have the user drag the gearstick to the right gear but doing that while having your fingers awkwardly placed on the keyboard wasn't ideal..

Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?

That solution would require a mod that adds a block that outputs a redstone signal between 0 and 15 based on the position of the analog input.
Redstone should have enough resolution to avoid stalling, but it wouldn't be smooth.

Yep. That's the only solution I can think of. A peripheral that records controller/pedal input and the computer can read that.
MineRobber___T #8
Posted 26 August 2017 - 02:21 AM
-snip-
There's just..something..missing..It doesn't feel right..
I KNOW! NO SOUND!! UGHHHHHH! Driving me crazy!
-snip-

I suggest adding a condition where, if speakers are attached, you play a low note (like
speaker.playNote("guitar",100,0)
) continuously. That way, you get the hum of the running car.
Dave-ee Jones #9
Posted 26 August 2017 - 12:52 PM
-snip-
There's just..something..missing..It doesn't feel right..
I KNOW! NO SOUND!! UGHHHHHH! Driving me crazy!
-snip-

I suggest adding a condition where, if speakers are attached, you play a low note (like
speaker.playNote("guitar",100,0)
) continuously. That way, you get the hum of the running car.

Yeah I was thinking about that, and it would be fun to implement the rev sound.
Lupus590 #10
Posted 26 August 2017 - 01:00 PM
I wonder what drivers would think of this, whether it's realistic or not.
Something which immediately sticks out is that you can't control how far down the clutch is, so it can't sit at the "biting point". None the less, it's a pretty cool program. Now we need a way to rig up some gaming pedals :P/>.

Yep, that's the thing. Unfortunately the only way I could fix that is utilise the mouse and use a dragging feature or something.

I was actually looking at my racing pedals in the other corner while making this going "sorry, you can't help me with this one :(/>". If only..

Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?

Oo that would be interesting..I kinda wanted to use the gearstick for dragging as well, like have the user drag the gearstick to the right gear but doing that while having your fingers awkwardly placed on the keyboard wasn't ideal..

Now we need a way to rig up some gaming pedals :P/>.

What's the easiest way to make analog redstone signals? Would redstone have enough resolution for controllers?

That solution would require a mod that adds a block that outputs a redstone signal between 0 and 15 based on the position of the analog input.
Redstone should have enough resolution to avoid stalling, but it wouldn't be smooth.

Yep. That's the only solution I can think of. A peripheral that records controller/pedal input and the computer can read that.

or you make use of http to communicate with a non-CC program which can use real world hardware
The Crazy Phoenix #11
Posted 26 August 2017 - 08:41 PM
Wouldn't that have the massive overhead of opening the socket every time you try to read from the controller.

You might get away with partial responses (allowing you to send an infinite amount of data in response to 1 GET) but that's only if CC supports it, and the server wouldn't know when to stop sending inputs.
H4X0RZ #12
Posted 27 August 2017 - 02:27 AM
Wouldn't that have the massive overhead of opening the socket every time you try to read from the controller.

You might get away with partial responses (allowing you to send an infinite amount of data in response to 1 GET) but that's only if CC supports it, and the server wouldn't know when to stop sending inputs.

Depending on your CC version and the mods you have installed you can use actual (web)sockets (the mod in question is CCTweaks). I even got a "native" discord client somewhat working that way.
Dave-ee Jones #13
Posted 27 August 2017 - 07:29 AM
-snip-
or you make use of http to communicate with a non-CC program which can use real world hardware

Yes, that's definitely possible but would be quite slow. Even if it was for an internal HTTP request on an internal website it was still be pretty slow..The best way would be for someone to make a custom peripheral that can make sound, obviously being able to be 'used' by a CC computer. Would be very nice. A noteblock could work I suppose but it would sound quite weird..
SquidDev #14
Posted 27 August 2017 - 07:53 AM
The best way would be for someone to make a custom peripheral that can make sound, obviously being able to be 'used' by a CC computer. Would be very nice. A noteblock could work I suppose but it would sound quite weird..
Could you put a custom sound is a resource pack, and play it using an iron noteblock/speaker (or anything that supports playing sounds by resource name)? It's a bit of a faff, but easier than creating a new mod.
Dave-ee Jones #15
Posted 27 August 2017 - 10:48 AM
The best way would be for someone to make a custom peripheral that can make sound, obviously being able to be 'used' by a CC computer. Would be very nice. A noteblock could work I suppose but it would sound quite weird..
Could you put a custom sound is a resource pack, and play it using an iron noteblock/speaker (or anything that supports playing sounds by resource name)? It's a bit of a faff, but easier than creating a new mod.

Yep, good idea. If someone else made one I'd be happy to add it in! I say that because I don't know how, and it might be better if someone else does it.
Lupus590 #16
Posted 27 August 2017 - 01:51 PM
-snip-
or you make use of http to communicate with a non-CC program which can use real world hardware

Yes, that's definitely possible but would be quite slow. Even if it was for an internal HTTP request on an internal website it was still be pretty slow..The best way would be for someone to make a custom peripheral that can make sound, obviously being able to be 'used' by a CC computer. Would be very nice. A noteblock could work I suppose but it would sound quite weird..

I was thinking more of for the pedals/analogue input.
Dave-ee Jones #17
Posted 28 August 2017 - 01:15 AM
-snip-
or you make use of http to communicate with a non-CC program which can use real world hardware

Yes, that's definitely possible but would be quite slow. Even if it was for an internal HTTP request on an internal website it was still be pretty slow..The best way would be for someone to make a custom peripheral that can make sound, obviously being able to be 'used' by a CC computer. Would be very nice. A noteblock could work I suppose but it would sound quite weird..

I was thinking more of for the pedals/analogue input.

Yeah, sorry, I just trailed off somewhere, but it would still be the same kinda thing..But you could still do a similar thing with the block that catches the analog input and the CC computer can read it. I would love it if I had that working, because I could port it to CraftOS 2.0 (maybe..) and make a driving game based on this, with the analog input. Would be pretty nice, until you realise DiRT Rally is a better option and start playing that instead :P/>

I've got a seat made of PVC pipe that has a Logitech G29 wheel, base and shifter which is a lot of fun - even more so with VR (just can't play it as long :wacko:/>)
Edited on 28 August 2017 - 05:16 AM
Dave-ee Jones #18
Posted 28 August 2017 - 04:46 AM
UPDATE!
Okay so I've added speed! It wasn't OVERLY hard but unfortunately it is a theoretical speed based on gear ratios, RPM and tyre diameter. You can change defaults in the config at the start of the program if you wish, have a play, but I wouldn't advise it unless you know what you're doing or you know that what I've done may be stupid and/or silly.

You can tell it's theoretical when you change from 1st to 2nd and your speed jumps by like 10mph..There's no acceleration (smooth speed acceleration, anyway) so you can go from Neutral to 1st gear and be at 20mph from 0 instantly. Bit annoying but I can't work out how to have a smooth acceleration while gear changing, as the speed is a theoretical speed based on what I said earlier, it doesn't take into account current speed/gear/RPM.

If you play around with the tyre diameter and the gear ratios you can see what it does to the speed/RPM as well, so have a play with that! Comment your fastest speed setup, as well, I'd be interested to see if anyone can get a nice gear ratio setup with a good tyre diameter. Keep in mind even if you get your speed up to like a crazy 100000 or something your car will never make that speed because you have to take into account the maximum power output your car has. Might implement that at some point too, not sure though - it's a lot of work.

Any suggestions would be great! :)/> For now, I hope you enjoy the speed!

EDIT: Was playing DiRT Rally and my back wheel came off, so I ended up revving it up to like 8000rpm and it said my speed was 120km/h when I could clearly see I wasn't moving 20km/h..So that's also theoretical as well :P/>
Edited on 31 August 2017 - 05:09 AM