- Home /
No headbob when jumping
I got this script from unity answers.
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 (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;
}
}
How would I make it so that when I am jumping and holding down a movement key it wont do the headbobbing????? PLEASE HELP
Remove the code which is bobbing (changing the vertical height of) the head (presumably whatever the camera's attached to).
Answer by Tony_T · Mar 27, 2014 at 01:47 PM
Within
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0)
use
if (charController.isGrounded)
I think this will work only if your character is touching the ground. Try it and let me know.
Your answer
Follow this Question
Related Questions
Timer help please 1 Answer
How do you collect a GameObject and make it Spawn somewhere else? 1 Answer
Simple LOD Manager Mesh to Mesh (Smoothly Fade) 0 Answers
Have a 'Torch' script toggle on and off 1 Answer
I need help instantiateing a bullet 0 Answers