Quantcast
Channel: Latest Questions by JusticeAShearing
Viewing all articles
Browse latest Browse all 12

Why Is My Movement Script Only Partially Functional?

$
0
0
In my movement script, coded in C#, the horizontal axis controls are fully recognized and their required actions carried out. However, my vertical axis controls are either ignored or not carried out properly. Specifically, my forward key (inputManager.isInput[0]) does absolutely nothing, while my backward key (inputManager.isInput[1]) performs the jump function of (inputManager.isInput[4]). This movement script was created by adapting the movement script on the Unity Scripting Reference, that script was found in the page entitled 'CharacterController.Move'. My adapted script is as follows: using UnityEngine; using System.Collections; public class Movement_V : MonoBehaviour { public float speed = 6.0F; public float jumpSpeed = 8.0F; public float gravity; private float horizontal; private float vertical; private Vector3 moveDirection = Vector3.zero; public custom_inputs inputManager; public Menu_Control_CS menuControl; void Update() { CharacterController controller = GetComponent(); if(menuControl.mainMenuOn == true) { gravity = 0; } else { gravity = 20; } if(inputManager.isInput[0]) { vertical = -1; } else if (vertical 0) { vertical -= 1; } if(inputManager.isInput[2]) { horizontal = -1; } else if (horizontal 0) { horizontal -= 1; } if (controller.isGrounded) { moveDirection = new Vector3(horizontal, 0, vertical); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (inputManager.isInputUp[4]) { moveDirection.y = jumpSpeed; } } moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); } } The input manager array: inputManager.isInput[4] is used to find when certain keys being pressed. It is the equivalent to: Input.GetKey(KeyCode.Space) Since the horizontal axis is working but the vertical is not, I do not understand why the problem exists. Although I will continue trying to solve this, I would appreciate any help.

Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles





Latest Images