How to make a speedometer in GameBlender

-This tutorial assumes you know how to model with Blender and display text(bitmap fonts)in GameEngine.

1)DIGITAL SPEEDOMETER

- Open Blender,create a plane and make it to display text(the plane will be our display for the speed).Select the object want to calculate speed(car,airplane,missile.....)and press F8 to go in realtime buttons.Add an always sensor.Attach it to a Python Controller.Split your 3D window and open a Text window(Shift-F11).Put this script:

import GameLogic
import math
cont4=GameLogic.getCurrentController()
owner=cont4.getOwner()

speed=owner.getVelocity()
speedt=math.pow(speed[0],2)+math.pow(speed[1],2)+math.pow(speed[2],2)
speedtot=(math.sqrt(speedt))*2


vel=cont4.getActuator("vel")
vel.setProperty("Text")
vel.setValue(str(abs(int(speedtot))))
GameLogic.addActiveActuator(vel,1)

-Name it and put the name in the Python Controller.Select plane and in the realtime buttons add an Property Actuator named "vel".Hold pressed Shift and select the car.Connect the Python Controller of the car with the Property Actuator of the Plane.Now if you move the car(or what it is) ,will see the speed displayed on the plane.In the script above the speed is multiplied by 2.This is done to give more reality.

2)WATCH SPEEDOMETER

-Open Blender,model a lancet with the center in the lowest part.Split the 3D window and open the Ipo Window.Give to the lancet the full rotation you want to have in 36 frames(the rotation depends on the speedometer you want to make,ususally it goes from 225 to -45 deegres):

-Select the object to which the speed has to be calculated.As in the digital speedometer add to it an Always Sensor and attach to it a Python Controller.In it you 'll put the script below:

import GameLogic
import math
cont=GameLogic.getCurrentController()
owner=cont.getOwner()

speed=owner.getVelocity()
speedt=math.pow(speed[0],2)+math.pow(speed[1],2)+math.pow(speed[2],2)
speedtot=(math.sqrt(speedt))*2
speedfinal=int(speedtot*36/300)

ve=cont.getActuator("ipoact")
ve.setType(1)
ve.setStart(speedfinal*0.8)
ve.setEnd(speedfinal)
GameLogic.addActiveActuator(ve,1)

-Than select the lancet and add an Ipo Actuator named "ipoact"(without changing nothing)and connect it with the Python controller .

-In the ImolaRace Game in the Games section there are examples of both speedometers.Happy Blendering!!