- Home /
First Person Head Bobble Issues
var head:CharacterController;
var toTheRight = false;
function Start(){Bobble();}
function Bobble(){
while(true){
if(head.isGrounded && head.velocity.magnitude > 3){
var camera = GameObject.FindWithTag("MainCamera");
if(toTheRight == false){
for(var i=0;i<100;i++){ //goes to the top-right
camera.transform.position += Vector3(0.001,0.001,0);
yield WaitForSeconds(0.0001);
}
toTheRight = true;
}
else if(toTheRight == true){
for(var ix=0;ix<100;ix++){ //goes back to original pos
camera.transform.position -= Vector3(0.001,0.001,0);
yield WaitForSeconds(0.0001);
}
for(var ixx=0;ixx<100;ixx++){ //needs to go to the top-left
camera.transform.position -= Vector3(0.001,0.001,0);
yield WaitForSeconds(0.0001);
}
toTheRight = false;
}
}
else{yield;}
}
}
You know how there are head bobbling whenever you walk? Well I'm having some issues:
-It will head to the top right at first, but then hit left more and more and then get back up to the right, but it will keep going "lefter" and lefter, which is because I cannot think of how to phrase the Vector3 line where I put the comment "needs to go to the top-left" -Not just this, but when you stop moving, the for loop will still continue and I cannot think of a way to get around that and make it stop immediately. -It's also an incredibly unrealistic head bobble movement and I'll need improvement for it
Can anybody help fix this mess please? Or a link where I could freely find a good head bobble movement for first person? It would be great. Thanks.
Just a suggestion, when I try to create a bobble effect i usually just open the animation editor and make a looping animation upon the camera. (you can make multiple ones and short one time animations to cross fade in at random intervals to make it less static). It is much easier to open the editor and make small edits then it is working with numbers the way you are. Hope this helps.
Your answer
Follow this Question
Related Questions
Character too floaty after jumping and grappling.,Grapple too floaty 0 Answers
Character Controller Movement 0 Answers
My character controller and vehicle (spaceship) move at same time 1 Answer
Character controller + animation of different meshes making one character 1 Answer
Bug, characters always moving to the right in unity games 1 Answer