- Home /
Main Camera flys up on "play"
My main camera is at a good position, but when I hit play to test my game the camera fly's up like 1 or 2 feet and now my character looks way to tall. Even if I try and bring it down it fly's back up no matter what. I changed my height to 1 but then I sink into the ground. So its 2... Any ideas?? I May have found the issue but don't know how to fix it. It happens when I add "this" wobble affect. I really need a wobble FX otherwise I'm just gliding across the floor. Looks really unrealistic.
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;
}
}
Please post any code which affects the camera, formatted using the 101/010 button.
Looks like the script is intended for use on a camera which is a child of a player controller. If that's already the case, I'm guessing you need to change the midpoint variable to something suitable.
Yeah, I put it on my camera. I'm not familiar with midpoint variable... lol Thanks for responding though!
midpoint is the name of a variable in the script you posted.
Your answer
Follow this Question
Related Questions
How to set main camera? 3 Answers
Weird build issues - any suggestions? 2 Answers
object collision attatched to camera 1 Answer
Camera.main - what does this mean in a split screen game? 1 Answer