how to make speed meter (Python)

  1. What I am asking is that it is very easy, but I do not know anything about Python … what I need is for a property (“Zfall”) type float, to show the speed in the z axis.
  2. and another property (“Move”) also float, show the speed of movement of the object on any axis.
  3. and finally I want to know how to put in python that an object to press W moves on the Y axis … but putting in python the limit speed, acceleration and initial speed.
    Beforehand thank you very much…

move = own.linearVelocity
zFall = move[2]

if cont.sensors[“Keyboard”].positive:
…if move[1] < 10 #speed limit:
…own.applyForce([0,1,0], True)

Or you can use own.linVelocityMax = 10 #speed limit

but please you could put the scripts separately and complete, which as I said I do not know anything about python …


import bge

owner = bge.logic.getCurrentController().owner

owner["Zfall"] = owner.getLinearVelocity().z

It requires the object to by a physics object (dynamic, rigid body, …)

How do you want to provide this “any axis”?
I guess you mean the speed of the object (regardless of the direction).


import bge

owner = bge.logic.getCurrentController().owner

owner["Move"] = owner.getLinearVelocity().length

It requires the object to by a physics object (dynamic, rigid body, …)

I do not understand what you mean with this.

#always-true pulse
#keyboard - w_key
#connected to python module -&gt; scriptname.speed
#put property-float named current_speed on the object running this script

def speed(cont):
    own = cont.owner
    #set to your liking
    speed_limit     = 20.0
    acceleration    = 0.2
    #grab keyboard sensor
    w_key = cont.sensors['w_key']
    #grab the speeds
    x,y,z = own.localLinearVelocity

    if w_key.positive and y &lt; speed_limit:
        y += acceleration
    elif y &gt;= acceleration:  
        y -= acceleration  
    #use y to get the y speed, or use own.localLinearVelocity.length
    #to get the speed no matter what direction   
    own['current_speed'] = own.localLinearVelocity.length
    #set the speeds 
    own.localLinearVelocity = [x,y,z]