I’ve made a simple hallway runner movement with walljumps, and when testing it in the small preview window, everything ran smoothly with no problems. However, whenever I try testing it at a higher resolution (“maximize on play” option or exported fullscreen), the character controller’s movement updates less frequently. At first, I thought it was a huge framerate drop, until I put an animated part of the level onscreen and saw that it was moving at the desired framerate.
To move my character, I simply use a Vector3 called moveDirection, and use “controller.Move(moveDirection * Time.deltaTime);”. Does anyone know what I’m doing wrong?
Code:
float leftvelright = 0.0f;
public float jumpSpeed = 10.0F;
public float gravity = 30.0F;
private Vector3 moveDirection = Vector3.zero;
public static float runSpeed=5.0f;
public static bool dead = false;
void Update () {
if (runSpeed < 20.0f) {
runSpeed = runSpeed + 0.05f*Time.deltaTime;
print (runSpeed);
}
if (dead == true) {
leftvelright = 0;
}
//print (leftvelright)
CharacterController controller = GetComponent<CharacterController>();
if (leftvelright < 5 && leftvelright >= 0 && Input.GetAxis ("Horizontal") > 0 || leftvelright > -5 && leftvelright <= 0 && Input.GetAxis ("Horizontal") < 0) {
leftvelright = leftvelright + (Input.GetAxis ("Horizontal") * Time.deltaTime * 50);
//steer
}
if (leftvelright <= 5 && leftvelright < 0 && Input.GetAxis ("Horizontal") > 0 || leftvelright >= -5 && leftvelright > 0 && Input.GetAxis ("Horizontal") < 0) {
leftvelright = leftvelright + (Input.GetAxis ("Horizontal") * Time.deltaTime * 50);
//reversedirection
}
if (Input.GetAxis ("Horizontal") == 0 && leftvelright < 0) {
leftvelright = leftvelright + (0-leftvelright)*10*Time.deltaTime;
//stop
}
if (Input.GetAxis ("Horizontal") == 0 && leftvelright > 0) {
leftvelright = leftvelright - leftvelright*10*Time.deltaTime;
//stop
}
if (leftvelright > 10)
leftvelright = 10;
if (leftvelright < -10)
leftvelright = -10;
if (controller.isGrounded) {
moveDirection = new Vector3 (leftvelright, 0, 0);
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.x = leftvelright;
moveDirection.y -= gravity * Time.deltaTime;
moveDirection.z = runSpeed;
controller.Move(moveDirection * Time.deltaTime);
}
void OnControllerColliderHit(ControllerColliderHit hit){
if (hit.gameObject.tag == "Wall") {
moveDirection = new Vector3 (leftvelright, -1, 0);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
if (moveDirection.y > jumpSpeed)
moveDirection.y = jumpSpeed;
leftvelright = -leftvelright * 2.0f;
}
}
}