Re:Rolling stone

#177992

OriginalBBB
Partecipante
  • Blenderista
  • Conversazioni totali307

L’errore che facevo era non attivare il true level triggering, così prendeva la velocità  al primo istante, 0, etutto finiva nel silenzio 😀

ho usato questo codice ora, suggeritomi su blenderartist. potevo arrivarci anch’io, solo mi fustrava che getlinearvelocity non sembrava funzionare, per il motivo sopra.

Ora userò il metodo i ccddffxx per determinare gli impatti, usaare cioè una palla sensore più grande.

Quote:
import math as M

GL = GameLogic

cont = GL.getCurrentController()

obj = cont.owner

ground = cont.sensors[“touchground”]

#The sound actuator

sound = cont.actuators[“roll_sound”]

#The range of speeds your vehicle will be going

speedrange = 3

#The range of pitch you want the sound to be

pitchrange = 1.5

#The minimum pitch

minpitch = .8

#the range of volume the sound will play

volumerange = 1.5

#the minimum volume

minvolume = 0

vspeed = obj.getLinearVelocity(0)

#The current speed of your vehicle

speed = (M.fabs(vspeed[0])) + (M.fabs(vspeed[1])) + (M.fabs(vspeed[2]))

#The new pitch your sound will play at

newpitch = (speed/speedrange)*pitchrange+minpitch

#the new volume the sound will play at

newvolume = (speed/speedrange)*volumerange+minvolume

sound.pitch = newpitch

sound.velocity = tuple(vspeed)

#If the ball is touching the ground, use the dynamic volume level

if ground.positive:

sound.volume = newvolume

#if the ball isn’t touching the ground, make the sound silent

else:

sound.volume = 0

cont.activate(sound)