Vehicle_demo

Hi,

I made a vehicle demo, with the vehicle wrapper. Since some of you may be planning to make your own car game I thought it would be good to show how I would do it.

The demo will be updated when new features are added. My final intension is to create a blend with several vehicles on a hidden layer, that can be loaded and added to a scene. The player then can walk to a vehicle and drive it, park, go to another vehicle … Also I hope to add a menu to change controls. But that’s for later.

Controllers (keyboard and gamepad) can be edited in the ‘controllers.py’ script. Vehicle templates can be added and edited in the ‘vehicles.py’ script. The game properties of the vehicle object (in this case ‘Car’) hold references to the vehicle template and the names of the vehicles body, tires, steering wheel and cameras, and the lights of the scene. When the script starts the lights will be parented to a vertex child of the vehicle, and the car default camera will be set to the active camera.

In order to understand the script you have to know what classes and modules (can) do and you have to know about dictionaries, lists, matrices, vectors, radians, …

For better turning control the demo is best played with a game pad with stick.

The audio files are public but may not be sold.

I hope this will be helpful to some of you.

Edit_1:- small fix (was moving forward while braking)
Edit_2:- fix when upside down (skid);- fix when turning on local X-axis (crash);

  • fix when turning on local Z-axis (gear);
  • impact dependent volume of crash
  • cleanup

Edit_3: to do: lights; interior

Attachments

Vehicle_demo.zip (402 KB)

preserved for vehicle with player demo

I have made a character that i was controlling get in and out of a vehicle using only logic bricks.Are you going to do it with python?

Yes. The general idea is this: HorseMount_01.blend (92.4 KB)

Where is the controls or is it just code?I hope your going to make doors that open when the character gets near and presses a button.It would be great if it could be two player.Another character could then get in and be driven places.

use the arrow keys to move the ‘player’ to the side of the ‘horse’ then press return

Oh yes it worked.

Thanks, [KiT]

The idea is that on a key press near to the door the character opens the door realistically, enters the vehicle, closes the door and starts the engine. After this has happened you can drive. Also the way around, on a key press the car will slow down quickly (if moving), the character will shut down the engine, open the door and get out, then close the door. Then the character can walk to the store…

All classes in the script (except the main module) are stored in the game object so it’s possible to use the script in a multi-player game, with some small adjustments in the ‘Scene’ class and the ‘Input’ class and ‘controller.py’.

Right now the class treats the lights and cameras as part of one screen. For a multi-player the lights wouldn’t be a parented to the vehicle. Depending on the distance between two vehicles, there would be one Sun if the distance is small, and two Suns if the distance is great. An additional script would manage adding and removing suns and their positions relative to the vehicle.

For the controls every vehicle would have a property referencing to a controller template (which can be selected in game, also edited if it comes to that). For two game pads it could be the same template, but for the keyboard obviously the key controls can’t be the same for both players.

@ dav98:

As been requested here are two example blends that only deal with the gears and the motor sound. One uses the Python aud module to get the motor sound, the other uses a sound actuator. Hope this helps.

Edit: For the one with the actuator delete the first two lines, since they are not needed. I just forgot about it. Sorry.

Edit2: A new updated file of the older file is added. This contains better structured code. I strongly recommend to go with this because the older file shows bad practice of storing classes into game properties.

Edit3: Removed one line.

Attachments

Vehicle_gear_motor_sound.zip (206 KB)Vehicle_gear_motor_sound_python_updated.zip (125 KB)

Looks very interesting, but for some reason, I can’t make it work. The car moves by gravity up and down the hill until it stops, but I can’t make it turn, change cameras etc, no response from the keys.

Am I missing something?

I don’t have a game pad, so i’m trying with the keyboard.

Hi hubar, sorry it didn’t work out. What Blender version are you using? I’m using 2.68a and there seems to be nothing wrong with the movement or keyboard controls. As a reminder, the keyboard controls can be adjusted in the controllers.py script.

Edit: Also if you could check the Console for errors. If there are, try to download the file again, maybe the file was corrupted? Or your blender version has bugs which 2.68a doesn’t have?

Same for me, I can’t control the car at all. 2.68a.

So strange. Are you sure you’re using the up/down/left/right arrow keys? I can assure you that I downloaded the file myself and played it without any problems. Anything in the Console?

Tried everything, no response :confused:

If there’s nothing in the Console, could you maybe check the following?

print(logic.joysticks[0]) #put this on line 2

It should say None.

Edit: Are you using Linux or Mac maybe? I’m using Windows 7.

Thanks.

Good news, I found the problem.

Using,

print(logic.joysticks[0]) #put this on line 2

here is what the console shows:

Blender Game Engine Started
Microsoft Microsoft® Nano Transceiver v2.0
default 0 kph, 39 kph, 75 kph, 111 kph, 147 kph
attempt for addWheel: suspensionRestLength0.075000 wheelRadius 0.275000, hasSteering:1
attempt for addWheel: suspensionRestLength0.075000 wheelRadius 0.275000, hasSteering:1
attempt for addWheel: suspensionRestLength0.075000 wheelRadius 0.275000, hasSteering:0
attempt for addWheel: suspensionRestLength0.075000 wheelRadius 0.275000, hasSteering:0
Blender Game Engine Finished

so, the script was detecting my mouse " Nano Transceiver". Removed the transceiver, tried again and it works.

Nice work Raco, i’ll give a good look at your file. You got some interesting solutions there.
Thanks for sharing.

Tested on Ubuntu 13.10 with blender-2.68a-linux-glibc211-x86_64

Thanks a lot for your reply, hubar!

Wow, I can’t believe my guess was right. But I wonder why a mouse (receiver) is detected as joystick input in the Blender Game Engine? Is this a bug, or is it been detected like so because the mouse receiver is also compatible with a wireless gamepad maybe?

Anyways, I’m really glad you find the solution, so I know I can prevent this from happening in the future. I have to find a way to detect only a gamepad or maybe give a warning about that in front. Probably I’ll have to implement a menu for the controllers so the game could be manually set to keyboard or gamepad.

As for the file itself. Another update is coming. Most importantly a fix for the skidding sound on line 502:

            elif <b>playing</b>:
                self.skidd_handle.stop()