- Home /
Question by
jeremy · Jun 26, 2012 at 10:52 PM ·
collisiongameobjectbutton
How to make movement on camera on button down.
Hi I need to know how to create a head bobbing movement on button down. For example I am using the First Person Controller for my game and I want it so when the player clicks the arrow keys to move, the camera will make a head bobbing movement, so that it gives the effect he is actually walking. If you can help me thank you very much i have no idea how to do this. Thanks
Comment
Answer by hesa2020 · Jun 27, 2012 at 03:01 AM
I dont tested it , but i think something like that should work :
void WalkingEffect() {
GameObject MainCamera = Camera.mainCamera;
if(MainCamera.transform.rotation.x>5){
MainCamera.transform.rotation = Quaternion.Euler(MainCamera.transform.rotation.x++,
MainCamera.transform.rotation.y, MainCamera.transform.rotation.z);
}else{
if(MainCamera.transform.rotation.x>5){
MainCamera.transform.rotation = Quaternion.Euler(MainCamera.transform.rotation.x--, MainCamera.transform.rotation.y, MainCamera.transform.rotation.z);
}
}
}