Quick Question, acceleration = delta_velocity/delta_time in python?

def accelerate(obj):
    delta_time = 1/bge.logic.getLogicTicRate()
    vel = obj.worldLinearVelocity
    old_vel = vel.copy()
    delta_vel = vel - old_vel
    acc = delta_vel/delta_time
    return acc

Is this correct?

you will need to store

own[‘Last’] = own.worldLinearVelocity.copy()

if ‘Last’ not in own etc.

Yes, it sounds reasonable.

As BluePrintRandom indicates, you need a way to get the velocity from the previous frame.


def calculateAcceleration(object):
    timeDifference = 1 / bge.logic.getLogicTicRate() # s
    currentVelocity = object.worldLinearVelocity
    lastVelocity = getStoredVelocity(object)

    velocityDifference = currentVelocity -  lastVelocity # Bu/s
    accelaration = velocityDifference / timeDifference # (Bu/s) / s = Bu/s²
    return accelaration 

def getStoredVelocity(object):
   return object.get("_stored.velocity", object.getLinearVelocity())

def storeVelocity(object):
   object["_stored.velocity"] = object.getLinearVelocity().copy()

Due to the fact that you need the velocity from the previous frame, you have to ensure to call storeVelocity() the frame before you call calculateAcceleration() (these are two separate operations).

Thanks guys, I really need to keep that in mind, I’m sure I made that same mistake not long ago lol