How does one find the local velocity of an object? I’m trying to make a movement script that limits objects to a maximum speed.
import math #get velocity ( = x,  = y,  = z), so if you want just x-velocity type owner.getVelocity() speed=owner.getVelocity() #calculate total speed (x+y+z velocity) speedtotal=math.sqrt(math.pow(speed,2)+math.pow(speed,2)+math.pow(speed,2))
Thanks, but I don’t think that’s it. I searched the forum and found some code that I converted to a function. It gives velocity using the local coordinate system and is fairly accurate.
def getLocalVelocity(obj): #created by Ridiculous of BlenderArtists.org (as far as I know) with minor modifications by me Vel = obj.getLinearVelocity() Ori = obj.getOrientation() Vel = [ [Vel, 0.0, 0.0], [0.0, Vel, 0.0], [0.0, 0.0, Vel] ] LocVel =  #same as "LocVel = MultMatrix (Vel, Ori)" for r in range(3): row =  for c in range(3): row.append(Vel[r]*Ori[c]+Vel[r]*Ori[c]+Vel[r]*Ori[c]) LocVel.append(row) # I'm getting the sum of the values in the columns to get the # local velocity. It works, but it might be wrong because it's not # like getting the magnitude. As you may know, magnitude is always # positive, but I need negative and positive values, so I'm just using # the sum LVelX = LocVel + LocVel + LocVel LVelY = LocVel + LocVel + LocVel LVelZ = LocVel + LocVel + LocVel return [LVelX, LVelY, LVelZ] ### I added this code to test it cont=GameLogic.getCurrentController() own = cont.getOwner() print getLocalVelocity(own)
The topic was here: http://blenderartists.org/forum/showthread.php?t=49213 post #11
Oops, sorry… I somehow missed that local-word and thought you only want to know the velocity of the object. Looks like it gets much more complicated if you want local velocity.