Multiple sounds for car?

Hi,

How can I have one sound play while the key is pressed and when it no longer is have another sound play? For a car sound, stationary, in motion, and perhaps slowing down.

Is that possible with the bricks?

I would look into using python

to get familiar with python this is a good first lesson

import bge 

controller = bge.logic.getCurrentController()

own = cont.owner


brake = cont.sensors['BrakeKey']
throttle = cont.sensors['ThrottleKey']

engineSound = cont.actuators['EngineSound']
wheelSound = cont.actuator['WheelSound']
speed = own.localLinearVelocity.x
##this assumes x+ is forward

you can change a sound actuators pitch in real time or even what sound it plays using python

ThrottleKey-----------python------------EngineSound
BrakeKey--------------/______----------Wheel Sound

I would look into using python

to get familiar with python this is a good first lesson

import bge 

controller = bge.logic.getCurrentController()

own = cont.owner


brake = cont.sensors['BrakeKey']
throttle = cont.sensors['ThrottleKey']

engineSound = cont.actuators['EngineSound']
wheelSound = cont.actuator['wheelSound']
speed = own.localLinearVelocity.x
##this assumes x+ is forward

you can change a sound actuators pitch in real time or even what sound it plays using python

cont.activate(actuatorName)
will turn a actuator on

if sensor.positive:
lets you know a sensor is on

example

if throttle.positive:

engineSound.pitch=3+(own[‘Rpm’]*.05)
cont.activate(engineSound)

you can access a game objects properties using
object[‘property’]

like

own[‘Rpm’]

would be a property Rpm inside the game object running the script,

Thank you for the example.

My interest in the engine was to do without using the language. More importantly an AI system, if I have a cube racing a another object there is going to need to be some kind of chance system. There is nothing in the game development book about this, only a shark eating game using some AI.

As for the youtube site nothing.

nothing I make came from any book.

as a coder you learn, add pieces to your methods as you grow.

by knowing how fast the object is moving, and the gear ratio of the gear they are in, you know how many rpm the engine would be turning,

then you change the speed etc, from there with what is happening with the throttle,brake and clutch etc…

I would have

1.system to make engine noise while clutch in
2.system to control rpm/noise when clutch out
3.system to transition back from clutch out to clutch in

Think , try, fail, what went wrong? learn, repeat.

stuck? post what you have and ask for help.

I think this needs to be said.
Nobody knows what book you keep referring to, and frankly nobody cares and you sound like a 50+ year old anyway trying to relive his/her childhood. I am sorry man but your prime years are gone, you’re gonna have a hard time learning new things (clearly, judging from your posts).
I mean come on, you refer to youtube as “youtube site”. Really?
Everybody keeps trying to explain to you how things work but you still can’t get it. You sound like a child. You can’t even grasp the simplest of concepts. Do you have some sort of ADHD or other mental illness?

At the moment I have nothing other than one object with a couple of rotating wheels with the sound connected. I do have an actual smart car model.

Basic textured, probably will remain that way.

I think for now, a simple AI race game. No programming. Just to get something going. Anything else is too complex. I’m more inspired from some really basic old PlayStation race games for the moment, than Grand Turismo.

I’m sure I can make a AI using the bricks, I don’t know, how this would work. Sensor objects.

So a timer then the AI car drives off down a road, and the player controls the other.

Even a game that can seem very simplistic to the eyes of a noob has some very complex behaviors going on in the background.
So, you are better off learning how to program and make some complex AI.
Like in blender to make a car controlled by the user you have to use vehicle constraints etc. and for that you need to know how to program.
If you still want to stick to super basic, I guess you can make something like pacman or whatever.

So the bricks can’t be used to create a racing game? When I tried Lost in space the demo, there was no program code involved.

It is possible to create a shoot em up/hitting people game without programming code. I’m quite sure of that. The AI would animate and walk around randomly with talking phrases or what ever. Once hit react by running away, or perhaps defend themselves.

For me, that’s not simple.

I think the easiest way I could think of is for the people walking around (AI) without a Navmesh or python, is Always sensor and motion actuator to walk. use a ray >dist. 3, that looks for for property “Wall” to turn. Don’t place any obstacles in the scene, just some invisible walls to keep the AI from walking off into oblivion. Give the walls a property “Wall”. When the ray hits the wall, it changes to state 2 on the AI, state 2 uses a motion actuator to turn the AI on it’s Z axis. Then a delay to switch back to state 1. The delay determines the angle of turn. This will keep the AI from walking into a wall and getting stuck there. Very simple setup with no Python.

But maybe it don’t look so good.

For the car, I would use a servo Motion actuator, this will simulate acceleration. And then just simple motion to turn the car on it’s Z axis.
Not the best setup, but simple. There is a really old script in resources that will increase the pitch of a sound to simulate acceleration by a property. It makes for a really good engine rev. But it might be for 2.49, and it’s python.

Then I would use the add object actuator to fire a dynamic object on an inactive layer, as a projectile. Give the object a property called “bullet” Tho this isn’t the best setup, because collision sometimes won’t work. But it’s simple and no python. Using a ray would be more accurate.

When the property bullet or ray, hits the AI change it to state 3 where the AI either runs away, or shoots back.

Hmmm, maybe not so simple.

Because you would need another state on the AI, so they wouldn’t walk into each other. (state 4) And of course you would want to place objects in your scene to make it more interesting, but now the AI might get stuck on them. (state 5).
And then to choose randomly whether the AI should run or shoot back.

So you can see how a simple idea gets more complicated.

I wouldn’t expect it not to be that easy. But if it is quite doable, I will want to try that out. My interest in the game engine was the bricks in the first place.

http://pasteall.org/blend/index.php?id=43291 Here is a very simple car setup with engine sound. Its a wav file so its big, sorry, you can change it to MP3 if you like. And you can use the sound if you want. Thanks to Kendrick for the script. if for some reason the Pasteall.blend file is engine rev.php. just rename the blend to engine rev.blend. (right click blend file choose rename)

To everyone, The sound is my 95’ Yamaha Phazer 2 snowmobile (which I still have and runs good) from a game I made in 2.49 a very long time ago. recorded on a pocket tape recorder. Feel free to use it if you find it worthy, change it anyway you like, pitch, format, whatever.

I appreciate you’re input, but python code is still a must?

I’m not going to be able to achieve a racing game with the bricks? I played london racer 2 that is basic, there is even the one before that, that is even much more basic.