- Home /
strange character controller falling
this one is a bit odd. I'm new to character controllers so i have no idea what is happening I wrote a script but i don't really think you'll need it to understand my problem.
notice i use simple move to move my character around, it works great until he falls off the edge of a platform.
the character sometimes falls off normally, but other times he falls super far, around three times as far to be exact!
i can't explain it, but i know that i cant have that happening all help is apprecieated
here's my script, again i won't think you'll need it (i only stress that because i never read peoples questions who barf 100 lines of code)
var movespeed = 30;
var airtime = -1; // used to find out how much longer to lerp
var jumphieght = 10;//just in case we add like a "high jump boots item;
var jumptohieght = 0; //the hieght to jump from which they are right now
var controller : CharacterController;
controller = GetComponent(CharacterController);
function Update () {
//simple movement
if(Input.GetKey(upkey)){
controller.SimpleMove(transform.forward * movespeed * Time.deltaTime);
}
else if(Input.GetKey(downkey)){
controller.SimpleMove(-transform.forward * movespeed * Time.deltaTime);
}else{
controller.SimpleMove(Vector3(0,0,0));
}
if(Input.GetKey(rightkey)){
transform.Rotate(0,120 * Time.deltaTime,0);
}
if(Input.GetKey(leftkey)){
transform.Rotate(0,-120 * Time.deltaTime,0);
}
if(Input.GetKeyDown(jumpkey) && controller.isGrounded == true){
airtime = 10 ;
jumptohieght = jumphieght + transform.position.y;
}
if(airtime >= 0){
airtime += -1;
transform.position.y = Mathf.Lerp(transform.position.y, jumptohieght, 0.1);
}
}
oh yeah, i forgot to mention, the jumping works like that too. sometimes i jump really far, and other times not as far.
hope this helps
This is off topic but to save you potential headaches down the road if you try to get a variableHeight from this script, you've transposed the i and e in height in every case (height vs hieght). $$anonymous$$y guess is the issue is the $$anonymous$$athf.Lerp but I couldn't say for sure.
thanks, actually i do that because it allows me to type faster
I used to type fo r ward as foward, that's just how i did it. i will be sure to change that if it becomes a problem. i love mono developes find tool
is some other games I've played (albeit they weren't made in unity), I've come across this sort of problem in playing them. is this an unavoidable issue?
I don't understand the premise - clarify what you mean by 'the players falls three times as far'. Did you mean falls three times as fast?
Answer by rednax20 · Apr 28, 2014 at 07:35 PM
i figured it out, so i'll post the answer here for anyone else who happens to have this problem (which it sincerely surprises me that i haven't seen anyone else with this problem around the web.
my problem was on line 11
controller.SimpleMove(transform.forward * movespeed * Time.deltaTime);
this essentially moves the character forward. Time.deltaTime is used to make everything move at a uniform rate on all computers.
It does't make the rate uniform, but rather, moves the controller faster when the frames are longer. But, if the character jumps or falls of a ledge, physics take over. the physics will move the character at a good speed from the very last point he moved (in this case the moment before he jumped or fell).
this means that if the frames speed up or slow down the character will move faster or slower than normal for just an instant, but if that instant is right before when you jump or fall you will keep that speed for the duration of the fall, so you could go really far or hardly move at all.
So I can't use Time.deltaTime
to resolve this all i had to do is put the code in a fixed update, where things will move in at a fixed rate and increasing speed will not be necessary
Your answer
![](https://koobas.hobune.stream/wayback/20220613143253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help! Problems with Character.isGrounded in Unity 4.0.1? 3 Answers
Moving Platform and CharacterController.Move not working. The player falls 3 Answers
Character collider / physics bug in Unity 3.3 - falling through terrain / objects 5 Answers
Turn off CharacterControl Component Through Script? 1 Answer
Animation through graphics in FPS controller, weird character controller issue, NEED help! 0 Answers