Headbob is not working after camera shaking c# Firstperson
Hi! I'm making a first person game so i use the free asset package from the Unity. My problem is i put camera shaking script inside the camera of my first person character because in my game there is a situation that the ground will shake and you're going to die. The Camera shaking script is working and the game looks like the environment is shaking but after the shaking of the camera the HeadBob is not working anymore when i run. The headbob is working before the camera shaking when i run. I dont know how to fix it because i just placed the asset package and the first person character into my scene and play it.
public Transform camTransform;
// How long the object should shake for.
public float shake = 0f;
// Amplitude of the shake. A larger value shakes the camera harder.
public float shakeAmount = 0.7f;
public float decreaseFactor = 1.0f;
Vector3 originalPos;
void Awake()
{
if (camTransform == null)
{
camTransform = GetComponent(typeof(Transform)) as Transform;
}
}
void OnEnable()
{
originalPos = camTransform.localPosition;
}
void Update()
{
if (CoffeemakingButton.ShouldCameraShake)
{
if (shake > 0) {
camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount;
shake -= Time.deltaTime * decreaseFactor;
} else {
shake = 0f;
camTransform.localPosition = originalPos;
}
}
}
See my answer to this question about a similar issue: http://answers.unity3d.com/questions/949984/slight-leantilt-when-strafing-messes-up-mouselook.html
Besides anything else that's going on, you should add a level of abstraction separating input behavior from additional behaviors like shake, head bob, etc.
Isolating individual mechanical operations into their own distinct logic will make it easier to build, expand, and spot issues.
WRT your specific issue, if something works before an operation, and doesn't work after, trace down the problem using print() statements to report the status of variables to ensure they are what you expect them to be. Clearly you are inadvertently overriding the head-bob behavior with something you're doing to achieve shake-on-demand behavior. Placing these functions in the same script would be wise.
I got errors to your link please help me
Sorry, but the question you're trying to see was deleted. We're sorry, but you do not have permission to do the activity you attempted. If you believe this to be in error, please contact the site ad$$anonymous$$istrator(s).
Answer by WinterboltGames · Sep 09, 2016 at 01:33 AM
My Friend Just Go And Import The Character From Assets>Import>Characters And Boom It's Fixed!!!
Answer by WinterboltGames · Sep 09, 2016 at 01:32 AM
My Friend Just Go And Import The Character From Assets>Import>Characters And Boom It's Fixed!!!
Your answer
Follow this Question
Related Questions
Regarding transform.position in the roll a ball tutorial 0 Answers
why the camera rotate in the z axis 0 Answers
RigidBody First Person Controller Not Working 0 Answers
Rotate camera when colliding 0 Answers
Underwater Swimming 1 Answer