- Home /
Why won't Character Controller Move Forward while in the Air?
Hey guys, I was wondering if somebody could help out with this code. I am trying to get the player to move forward while they are not grounded.
I'm wanting the player to turn locally so I am using InverseTransformDirection
.
Here is my code:
moveDirectionForward = new Vector3(0,0,10)
moveDirectionForward = transform.InverseTransformDirection(moveDirectionForward)
moveDirectionForward *= speed
moveDirectionForward=Vector3.forward*Time.deltaTime*speed
controller.Move(moveDirectionForward * Time.deltaTime)
moveDirectionForward
has been declared as well.
Any help is really appreciated.
Thanks!
Answer by ShinyTaco · May 09, 2013 at 02:45 AM
// This works
if (!controller.isGrounded) {
var relative : Vector3;
relative = transform.TransformDirection(0,0,1);
Debug.Log(relative);
controller.Move(relative * Time.deltaTime * yourSpeed);
//Debug.Log(" NOT GROUNDED ");
}
Answer by robertbu · May 08, 2013 at 03:42 PM
What scripts are you using to drive the character controller? I don't believe it is the character controller itself that is causing you issues. Typically in the scripts that drive a character controller you will see a line like this:
if (controller.isGrounded)
And the movement code will be inside the 'if' statement. Comment out this line, and you should be able to move.
Sometimes the checks are done differently, but they are almost always named "IsGrounded" in some form. Search for this string if you cannot find the statement above.
In my Update function I have the above code inside of:
if (!controller.isGrounded) { // }
Not really sure what's wrong with the code.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101831im_/https://answers.unity.com/themes/thub/images/avi.jpg)