Tuesday, 28 January 2014

Unity 4 - Third Person Controller and Camera useage hints and tips

1.) First thing first, when applying the components "Third Person Controller" and even more importantly "Third Person Camera" BOTH scripts should be applied to your player object. "Third Person Camera" is not meant to be applied to a camera, as much as the name might suggest it.

If you attached the "Third Person Camera" script to a camera you probably got a message like the following:

Please assign a target to the camera that has a ThirdPersonController script attached.
ThirdPersonCamera:Awake() (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonCamera.js:58)

2.) If you can't find "Third Person" Controller or Camera look under Components > Scripts.

3.) If you leave the "Camera Transform" attribute under "Third Person Camera" blank the script will try to use the Main Camera automatically. If you have no main camera (for whatever reason) and don't assign a camera transform to it there will be issues.... With an error probably like the following:

MissingComponentException: There is no 'Camera' attached to the "something" game object, but a script is trying to access it.
You probably need to add a Camera to the game object "something". Or your script needs to check if the component is attached before using it.

4.) If you get the following error:
InvalidCastException: Cannot cast from source type to destination type.
ThirdPersonCamera.Awake () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonCamera.js:52)
...it is probably because there is a collider on your player object. Take off the collider. Something ("Character Controller" I assume) is adding automagically.

5.) If you get weird jumpiness when turning, make sure all the above it straightened out. Then make sure the Camera isn't a child object of the player... Who knows, maybe it got there when you were experimenting with the scripts initially? :p

No comments:

Post a Comment