- Home /
CharacterController Gravity
CharacterController.Move sets isGrounded to false. 1) Why? 2) With this code, if the player has been moving, their gravity begins to build up. When the player falls, they fall at a very high velocity. I tried using raycast to check if the player was actually grounded, but it didn't turn out working well.
#pragma strict
public var player : CharacterController;
public var gravity : float;
public var grav : Vector3;
function Update() {
if (!player.isGrounded) {
grav.y -= gravity * Time.deltaTime;
player.Move(grav * Time.deltaTime);
} else {
grav = Vector3(0, 0, 0);
}
}
So if your player is not grounded, you want him to fall by gravity, but slow the influence of gravity down (with you float value) the longer he is in the air ?
no. As the player moves, gravity increases. I don't want it to do that.
Try to change the - in +:
grav.y (-)(+)= gravity * Time.deltaTime;
And it's still not very clear what the behavior of the character should be: "When he is in the air he should fall down linear?" Or "When he is in the air he should fall down but not so fast as gravity will make him fall?" Or "When he is in the air he should fall down like gravity want's it to but with a maximum fall speed, so when he falls down faster than 2m/s it should sray that velocity?"
Answer by cumhuryozcan · Dec 16, 2012 at 11:35 PM
As for the second question, change the line
grav.y -= gravity * Time.deltaTime;
to
grav.y = -gravity * Time.deltaTime;
In other words, delete minus sign before the equals sign and put it next to gravity. This will solve the "falling too fast" problem. What you do wrong was increasing the gravity effect every frame. After a few frames (in less than a second) your gravity reaches an extremely large value and this causes the player to move too fast. Then delete the else part as you wouldn't need it. I also believe that you do not need to multiply the value with Time.deltaTime two times so you may want to delete one of them.
For the first question, I don't believe that it is the Move method of the CharacterController directly causes the isGrouded to be false. What I suspect is, when you change the player's position (via Move), player actually becomes un-grounded. So I think the problem is actually about design of your scene.
Answer by Nirav-Madhani · Mar 22, 2015 at 03:26 PM
well , when its about Gravity ,Character Controller has it already and you just need to trigger it Something Like This
var controller : CharacterController = GetComponent(CharacterController);
controller.SimpleMove(Vector3 .forward * 0);
Your answer
Follow this Question
Related Questions
when i try using .SimpleMove my object jumps back to its starting position 0 Answers
Vector3.lerp doesn't work 1 Answer
Move empty object random 1 Answer
CharacterController.Move precision 1 Answer