Calculating speed


(Pooba) #1

I want to do a sort of glass breaking effect, but i only want the character to be able to break through at a specific speed or higher, so he won’t be able to just tap through it and a little fall onto the glass won’t break it, as a huge fall would. Will i need python for this? And if so, what’s the command to determine an object’s velocity?
Thanx
Pooba


(OTO) #2

Hello Pooba

In one of the old Blender demos, 2.14 i guess, there’s a “record speed” one.
It has a Python script that shows the speed of a sphere object
Try to find it ( or i can send it to you)

Bye
António


(Blender_owl) #3

Im not much of a python programmer and i know my code is wrong but here is an idea on how it works

import GameLogic

c = GameLogic.getCurrentController
s = c.getSensor
owner = s.getowner

if owner.speed == >50
#brake glass

heh, i mixed python, c++ and vb what a mess. But i hope you can figure it out, from the mosiac of languages i have written it in.


(ineedanewbi) #4

you know what someone should do?
someone should make a python script… it would be helpful to the community heres what i think

have an always sensor attached to a pythons script controller
the obj. should also have 3 properties

x, y and z… no duh…

and have the script “dump” the speed values of the object into these 3 properties so ppl who dont know how to use python can use these numbers.

i want this for myself too.
so if someone can create it, that would be great

thanks


(Tonberry) #5

Try using owner.getVelocity()

Found a tutorial on the net on “How to make a speedometer in GameBlender” @ http://space.tin.it/clubnet/arbenom/howto.htm

It uses a Python script! :slight_smile:

Oh… btw… first post for me on this forum! :))


(Ben) #6

Hi Pooba!
-This is the script that calculates speed(attached to an always sensor of the object you want the speed):

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)
owner.Speed=speedtot

You must add a float property named Speed and than can manage the object without python(with property sensor or actuator or expression controller).

Ben


(Pooba) #7

Thanx ben! works like a charm

Pooba


(ineedanewbi) #8

hey… like i said before, can some please make a script that puts the
x y and z
speeds into different properties?

this way we could do thinks like know when a car should “powerslide”, when the y value reaches over 5 the car starts to sqeal… we could do so much more with this… more than just the speed of an object in any direction…

please?
thanks in advance


(Ben) #9

Maybe this is what you’re looking for:

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)
owner.Speed=speedtot
owner.SpeedX=speed[0]
owner.SpeedY=speed[1]
owner.SpeedZ=speed[2]

Now you have four float props.Speed.SpeedX.SpeedY and SpeedZ

Ben


(ineedanewbi) #10

hey ben… thanks for the help… that script was good… but…

its still not exactly what i wanted. the speeds are … global i guesse u could say

i want the speeds to be local on the object using the script
so if a car moves forward north west east or south, the y speed should be positive and as i said before, if your X speed is greater than say 5, your tires will make a sqealing sound

thanks, just little furthur…


(saluk) #11

The properties in that script are saved to the object. Just make four props: Speed, SpeedX, SpeedY, and SpeedZ on the object, and you can use them in logic bricks. As long as you have an always hooked up to ben’s script, it will work.