So far, I have a simple First Person Shooter going. As our player looks up, they speeds forward. As the player looks down, they hustle backwards.
Here is the script to handle character movement:
float forwardSpeed = Input.GetAxis ("Vertical") * PlayerSpeed;
float sideSpeed = Input.GetAxis ("Horizontal") * PlayerSpeed;
verticalVelocity += Physics.gravity.y * Time.deltaTime;
if( characterController.isGrounded && Input.GetButton("Jump") )
{
verticalVelocity = jumpSpeed;
}
Vector3 move = new Vector3 (sideSpeed, verticalVelocity, forwardSpeed);
move = transform.rotation * move;
characterController.Move (move * Time.deltaTime);
Taking a deep look into the problem, I’m thinking that the engine is just applying gravity to the main camera’s down, and not a true down (This problem is no longer present when the gravity lines of code are noted out, and the velocity at which the player speeds is increasing). So, if the camera rotates up, the gravity’s vector does too. How would I make it so that gravity is applied to the player’s capsule collider, instead of the camera?