x-post with Stack Overflow. I have never posted here because I didn’t know it existed!
I am making a 3D platforming game and want my Game Object with CharacterController to jump. I am facing a strange issue where, despite the fact that my debugging text says that my object is being subjected to a vector in the y direction, I don’t see these results on the screen. There are numerous resources that seem to be available to make this work - but none of the approaches are working for me. I thought I’d ask here.
The character is a collection of game objects with a Transform (duh),Character Controller, RigidBody, and a script attached.
Rigidbody has “isKinematic” checked. All the rest in RigidBody is default.
The following is the salient part of my solution to making my character jump, rotate, and move in my Update loop:
first this is up top:
private Vector3 forward;
private Vector3 upvec = Vector3.zero;
Then here is my update:
void Update(){
CharacterController controller = GetComponent<CharacterController> ();
forward = Vector3.zero; //forward is a private Vector3 defined above
if (Input.GetKey ("w")) { forward = transform.TransformDirection (Vector3.forward); }
if (Input.GetKey("s")) { forward = transform.TransformDirection (Vector3.forward); }
if (Input.GetKey("space")) {upvec.y = jumpSpeed; //set to non-zero, I swear}
transform.Rotate (0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);//rotate
float curSpeed = speed * Input.GetAxis ("Vertical");//allows backwards
text_3.text = (forward * curSpeed).ToString (); //my own debugging
controller.Move (forward * curSpeed); //moves backwards/forwards
text_1.text = upvec.ToString ();
controller.Move (upvec * Time.deltaTime); //SHOULD move upwards but does not
}
The character does turn around and move forward/backward just fine. It just will not jump.
I tried to just isolate the important code to illustrate the problem. Let me know if there is anything I can do to clarify moreso.
Thanks