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!
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.
// 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 ");
}
[transform.TransformDirection in the Unity Docs] 1