How do I accelerate an object - like a car

I’m searching for help on how to accelerate an object. I could use a tutorial or even just a simple script example that shows how one could accomplish this using python.

I have tried scripting that looks like this but have always failed. :spin:

import Gamelogic

cont = GameLogic.getCurrentController()
own = cont.getOwner()
up = cont.getSensor("Up")
motion = cont.getActuator("Motion")

speed = 0
speedofacceleration = 0.1
currentspeed = motion.getLinearVelocity()

if up.isPositive():
     speed = currentspeed[1] + speedofacceleration

motion.setLinearVelocity(0, speed, 0, 1)
GameLogic.addActiveActuator(motion, 1)

I have a feeling my fault lies with the getLinearVelocity() function

I know its a simple problem and someone can take one look at it and solve it. In the mean time I am going to keep searching for a tutorial myself. :frowning:

For acceleration you will need a variable ‘time’.

Velocity = acceleration/timeOfAcceleration + Initial Velocity.

v = a*t + ship.getLinearVelocity(1)

you’ll need to do that for just one part of object.getLinearVelocity(0), so, if you wanted to accelerate on the +y axis, you will need a timer property (call it time), an acceleration property(acc for short), and you’ll need a sensor to apply the acceleration(WKey for example).

So in your script you would need to check if the WKey was just pressed, if it was, then you set time to zero. and then you can check if WKey is being held down, if it is, you do it this way:

velocity = acc/time + object.getLinearVelocity(0)[1]

object.setLinearVelocity([0.0,velocity,0.0], 0)

Have a look at: http://www.tutorialsforblender3d.com/Game_Engine/Vehicle/Vehicle_2.html
Unless you’re not doing an actual car.

I understand mostly. Thanks for the tips. I haven’t checked out the tut yet, but I will. :smiley: