- Home /
Question by
Erik-256 · Mar 20, 2014 at 11:57 PM ·
javascriptsoundif-statementsaudio.playsteps
Sound plays with step js script
I have found this script for bobbing the FPS head somewhere here in answer, I tried to add a little if cycle to have a little step sound I have every time this bobbing is at his minimum, but I can't make it work for some reason. The little debug log is never activated, even if I slow down the bobbing in order to easily stop at 1.60 or I make edit the value in 1.61, 1.62 or even 1.65 (which is the starting y position).
var bobbingSpeed: float = 1.5;
var bobbingDir: Vector3 = Vector3(0, 0.5, 0);
private var initPos: Vector3;
private var bobTime: float = 0.1;
private var TWOPI = Mathf.PI*2;
function Start(){
initPos = transform.localPosition;
}
function Update(){
var axes = Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
if (axes.magnitude>0.01){
bobTime += Time.deltaTime*bobbingSpeed;
movement = transform.TransformDirection(bobbingDir)*Mathf.Sin(TWOPI*bobTime);
transform.localPosition = initPos+movement;
}
if (transform.position.y==1.60)
{
Debug.Log ("bugger");
audio.Play();
}
}
Comment
Your answer

Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
EXTREMELY basic scripting question. 2 Answers
really strange thing with "if" statment not working well 1 Answer
Problem With Walking Sounds 1 Answer
Play sound on mouse enter 1 Answer