- Home /
Headbob jerky movement
Hey!
I have this headbob script that is attached to the maincamera on my character. It works well most of the time. But every now and then it starts hacking like crazy and sometimes it even stops altogether, and for some reason I can sometimes make it stop by changing the direction of my character. Almost the whole code is copy paste from another forum as I really hate writing these kind of scripts (avoiding stuff I should learn (y)). I've tried writing headbob scripts before and other similar stuff. But nothing really gets inside my head, I would much rather write some AI script or something hehe :-) So I would be very happy if someone could locate whats causing this since I just can't seem to find it.
Here's the code:
void HeadBob(){
waveslice = 0.0f;
Vector3 cSharpConversion = cameraTransform.localPosition;
if (currSpeed < 0.3f || (cControllerScript.isGrounded == false)) {
timer = 0.0f;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobSpeed * Time.deltaTime;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
float translateChange = waveslice * bobAmount;
float totalAxes = currSpeed;
totalAxes = Mathf.Clamp (totalAxes, 0.0f, 1.0f);
translateChange = totalAxes * translateChange;
cSharpConversion.y = midPoint + translateChange;
}
else {
cSharpConversion.y = midPoint;
}
cameraTransform.localPosition = cSharpConversion;
}
This gets called every update().
Your answer
Follow this Question
Related Questions
Camera follow a sphere which look at another object on the ground 0 Answers
Is it good idea to implement camera drag with UI drag event? 2 Answers
what is the best way to make an auto-scrolling camera?,auto scrolling camera setup? 0 Answers
Import animated camera from 3ds max 1 Answer
Smooth camera on moving platform 1 Answer