I am trying to get the angular velocity of an object in my game. Script is:
def main():
cont = bge.logic.getCurrentController()
# The KX_GameObject that owns this controller.
own = cont.owner
# for scripts that deal with spacial logic
own_pos = own.worldPosition
sce = bge.logic.getCurrentScene()
ob = sce.objects['Icosphere']
print("Icosphere angular velocity = ", obj.getAngularVelocity(False))
main()
I have tried many permutations but always get <Vector (0.0000, 0.0000, 0.0000)>. The object has a simple motion actuator set to 1 degree on the z-axis. Any clues on why I’m getting zero angular velocity?
also, simple motion rotation is not the same as set angular velocity
I think* that objects with rigid body sim, will still potenially spit out a angular velocity however* while under apply rotation- I am not 100% certain however
value = object.worldAngularVelocity
still gives me zeroes. Both objects (just a cube calling the script, and an icosphere with the motion actuator) are dynamic/actor.
I think* simple motion actuator and applyMotion/applyRotation in python are moving objects logically so the physics won’t return any change in velocity, linear or angular. A work around to this problem is to parent it with a child(rigid body physics) and read the velocity changes from the child object instead…
btw dynamic objects can return angular velocity too
guramarx: Still no joy. The child object (set to rigid body) still returns zero. Interestingly if I setAngularVelocity then getAngularVelocity it returns the velocity that I set. It begs the question though, if you can only get velocity if you’ve set velocity - what’s the point of it? What I’m trying to do is get how fast a wheel is spinning in a vehicle sim I’m working on. The wheels are spinning through the vehicle wrapper. Any other ideas I might try this?
cotax: I’m not sure I understand. The Icosphere has a physics id. I tested with print(ob.getPhysicsId()). But then what? Do I store that in a variable (say, obId) and then get obId.getAngularVelocity? (Actually, no, I tested it). So how does the physics Id help?
Your object is not of a physics type (I guess it is a static). Therefore the Physics Engine does not consider it as a movable object.
You set the location by yourself (via brick). In terms of physics this is not a motion. Therefore you can get a velocity as velocity requires a motion. In other words, you constantly teleport your object around.
Your object is not of a physics type (I guess it is a static).
Yes, yes it is. There are two objects: a cube and an icosphere. They are both dynamic/actor. They both have physics Ids. The script is attached to the cube and attempts to get the angular velocity of the sphere which has a simple motion actuator set to 1 degree zed rotation. The only way I can find to getAngularVelocity on the sphere is to setAngularVelocity on it first. But if I setAngularVelocity I don’t need getAngularVelocity because I already know what it is. All I want to do is find how fast a thing is spinning in the game engine. I thought getAngularVelocity would be it. Apparently not. The question now becomes, how do you find how fast a thing is spinning, with python in the bge.
OK, for future reference: My intention for this was to find a way to get the rate of spin of the wheels of a vehicle using vehicle wrapper. The toy script above was trying to get my head around why the wheel object persistently returned zeroes from getAngularVelocity(True), even when set to ‘rigid body’. I finally found that parenting an object to the wheel, setting the object to ‘rigid body’ and calling obj.getAngularVelocity(True) from the script gave me an answer. Thanks for everyone who contributed.