- Home /
Is There A Horizontal AND Vertical Head Bobbing Script?
I've Seen Many Instances Of A Vertical Head Bobbing Sript, But Not ONE That Has Vartical AND Horizontal Head Bobbing (Preferebly Left To Right And Vice Versa With a Vertical Curve Making It Go Up And Down And Across At The Same Time)
I've never noticed my head wobbling from side to side as I walk, but I guess it might happen! If you show us the code you're using at the moment, it should be trivial to add in an extra line to consider transform.position.x as well as transform.position.y
Heres $$anonymous$$y Script:
private var timer = 0.0; var bobbingSpeed = 0.18; var bobbingAmount = 0.2; var midpoint = 2.0;
function Update () { waveslice = 0.0; horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); if ($$anonymous$$athf.Abs(horizontal) == 0 && $$anonymous$$athf.Abs(vertical) == 0) { timer = 0.0; } else { waveslice = $$anonymous$$athf.Sin(timer); timer = timer + bobbingSpeed; if (timer > $$anonymous$$athf.PI 2) { timer = timer - ($$anonymous$$athf.PI 2); } } if (waveslice != 0) { translateChange = waveslice bobbingAmount; totalAxes = $$anonymous$$athf.Abs(horizontal) + $$anonymous$$athf.Abs(vertical); totalAxes = $$anonymous$$athf.Clamp (totalAxes, 0.0, 1.0); translateChange = totalAxes translateChange; transform.localPosition.y = midpoint + translateChange; } else { transform.localPosition.y = midpoint; } }
When writing code here, please press the "Code Sample" button(the one saying 101 010 and paste your code there. Then it'll be much easier for people to see what your code looks like ;)
Your answer
Follow this Question
Related Questions
How do I make my model's head and body rotate with the mouse? 2 Answers
Animated Haed while pressing button 1 Answer
How to not Render Character Head 1 Answer
Move player forward On a curve 0 Answers
Head Look Controller with camera 1 Answer