- Home /
Help with crouch script!
I have this crouch script I got from this link,
http://forum.unity3d.com/threads/48187-scale-character-controller-but-not-player
Here is the script,
var controller : CharacterController;
function Update ()
{
if (Input.GetKey ("c")) {
controller.height = 0.5;
controller.center = 0.25;
} else {
controller.height = 2.0;
controller.center= 0.5;
}
}
It's supposed to shrink the character controller capsule, so that it can go under objects. But I keep getting this, "Cannot convert 'float' to 'UnityEngine.Vector3" I'm not sure what is means.
I know the problem is with those controller.center pieces. But they are really important because they keep the character from sinking into the ground. Thanks for reading, this crouch has been bugging me for quite some time.
-Rov
Answer by jogo13 · Jan 07, 2013 at 03:58 AM
controller.center is a Vector3 so it will need to be reassigned in the form of a Vector3 (x,y,z)
//i'm guessing you want to just change the y so i keep the current x and z
controller.center = Vector3(transform.position.x, 0.25, transform.position.z);
Answer by Maulik2208 · Jan 07, 2013 at 05:04 AM
I think all you need is this just go to this and enjoy ------> Run & Crounch Script For Player
Don't forget to mark the answer if Found useful.....Cheers.....
Excellent link ! I used this for the OPs last question : http://answers.unity3d.com/questions/374157/character-controller-slide-action-script.html
I have seen other questions with people having trouble with the character collider falling through the terrain, I personally have never seen nor had this problem, search for these other questions to see how other users fixed the problem.
As I said, have seen this problem in alot of questions, but no real definitive answer. The main issue seems to be that the colliders are not correctly set up :
http://answers.unity3d.com/questions/17779/character-model-sinks-through-floor.html
http://answers.unity3d.com/questions/305913/first-person-character-falls-through-floor.html
http://answers.unity3d.com/questions/312147/crouching-and-falling-through-floor.html
http://answers.unity3d.com/questions/61791/character-controller-falls-through-floor.html
http://answers.unity3d.com/questions/topics/falling-through-floor.html
Thanks for the help, but I think this crouching script doesn't fit my existing script to well. I've decided to just disable the object's collider so I can slide under it, ins$$anonymous$$d of actually shrinking the player. Thanks for all the help though! If I ever need to do a crouch script, I'll certainly know how!
-Rov