eulerAngles/Grass freakout

The game I’m working is a 3rd person 3D platformer. I’ve found a weird issue, that I’ve since fixed (I think), but I’m curious if anyone knows why it happend in the first place.

Right now, the controller I’m using is a modified FPS controller. The camera has the Mouse Orbit script attached, targeting the controller. To keep the controller oriented with the camera, I have a line in the Controller’s script saying:

transform.eulerAngles.y = cam.transform.eulerAngles.y;

(cam being defined as the Main Camera).

For the most part this works fine. I’m not sure if its the best way but it does the job. But whenever the player moves around in terrain grass, the character starts spazzing out and has very hard time moving until you get out of the grass again.

I seem to have solved it by removing the Main Camera from the FPS controller’s group. (Original the camera was parented to the controller, like a normal FPS prefab). I can think of reasons why it wouldn’t have worked in the first place, but I don’t know why the grass would be the trigger for the freak out.

The webplayer showing the bug is here:

http://dl.dropbox.com/u/2000477/TreeWeb_broken.html

Use normal WASD/space keys to move and jump. Your character is the little ball of light. (It’s a plane that is supposed to rotate with the controller so it’s always facing the camera. When you enter the grass it starts spinning around randomly so you can tell it’s just a plane, although to the untrained eye it might just look like it’s intentionally flickering).

Edit: it doesn’t seem to always do the bug, so it might not be clear what I’m talking about. When it happens, the character starts spinning around rapidly.

Well, the docs do say not to set one element of eulerAngles separately like that.

–Eric

Fair enough. I wasn’t actually expecting it to work, but then it did and I didn’t notice any problems for a few days until the specific grass issue started happening.

reading the docs again it looks like I want to use this:

transform.eulerAngles = Vector3(0, yRotation, 0);

except that I’m not sure how to isolate the camera’s y rotation. Am I allowed to say:

transform.eulerAngles = Vector3(0, cam.transform.eulerAngles.y, 0);

or will that theoretically cause similar problems?

That’s fine, or you can also use:-

transform.eulerAngles = Vector3.up * cam.transform.eulerAngles.y;

…and possibly other things too. The main idea is that you set the whole vector at once.