- Home /
Question by
JuanDavisT21 · May 22, 2014 at 04:55 AM ·
android iphoneheadbob
How to headbob in mobile assets (joystick android)?
I need to Headbob my character in android device, but the script headbob
http://wiki.unity3d.com/index.php/Headbobber
doesn't work in android device because i must configure the joystick, i follow the steps of this answer
http://answers.unity3d.com/questions/459398/how-to-make-headbobber-on-joystick.html
but the compiler notice me an error with the unknow identifier waveslice and translate change, so, please help me writting me the answer, thanks
this is how i configure the script
private var timer = 0.0;
var moveTouchPad : Joystick;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;
function Update () {
waveslice = 0.0;
horizontal = moveTouchPad.position.x;
vertical = moveTouchPad.position.y;
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613145617im_/https://answers.unity.com/themes/thub/images/avi.jpg)