- Home /
Unity 4.3.4 completely freezes with third person script
Below is a very nice 3rd person camera script that I made following a tutorial on 3DBuzz. Whenever I put the TP_Controller.cs script on a biped or character and click play, the entire Unity 4 client freezes. I've tried contacting 3DBuzz to see if they could help see why Unity 4 is freezing but I've heard no response. Their forums are full of unanswered questions.
So is there anyone here that can test this on Unity 3 which is what 3DBuzz made it for. Or try it out for themselves to see why it's crashing? I don't even get a debug or error log message. It's just a hard freeze and I have to close Unity with TaskManager. It seems like there should be a failsafe built in to Unity avoid such a big crash.
To use the script all you need to do is attach TP_Camera, controller, and the motor C# scripts to a character. Make sure the helper.cs is with the other scripts. It'll automatically create a camera if one doesn't exist.
Helper.cs - http://pastebin.com/VwUghR0s
TP_Camera.cs - http://pastebin.com/X5JizCHE
TP_Controller.cs - http://pastebin.com/V5pHi1Mr
TP_Motor.cs - http://pastebin.com/NPGPEKkQ
If Unity freezing actually means Unity stops being responsive, this usually means one of the scripts has gotten into an infinite loop. The easy way to see this is to plaster Debug.Log()
messages everywhere, and look and see if any of them come spewing out of your scripts.
I went in and plastered Debug.Log all over the TP_Controller which is the script file in giving the problems. But the Console in the Unity editor freezes with Unity before it has a chance to say anything.
Is there any other way to debug this?
I narrowed it down to line 15 in the TP_Controller.cs script.
Line 15 is -
TP_Camera.UseExistingOrCreateNew$$anonymous$$ainCamera ();
Hmmm
Answer by Adamcbrz · Mar 19, 2014 at 01:38 AM
This is because your Helper.ClampAngle method.
These freezes are usually because of infinite loops.
I think you meant for it to be like this
do
{
// If angle is less than 360 - add 360
if (angle < -360)
angle += 360;
// If angle is greater than 360 - subtract 360
if (angle > 360) /***** you had -360 ****/
angle -= 360;
} while (angle < -360 || angle > 360);
AWESO$$anonymous$$E!!! Unity is no longer freezing but the camera is not following the character haha. Thanks a lot!
I also fixed a typo on line 145 in the TP_Camera.cs script.
UPDATE: I was missing an empty game object parented to the character named 'targetLookAt'. Now the camera follows the character.
Thanks a bunch!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Why can't I pass in void when trying to connect scripts? 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Material doesn't have a color property '_Color' 4 Answers
Footstep sounds not coming up when walking? (MOBILE) 3 Answers