Hi there
below is my code for FPS PlayerMove script. Screen also provided of component in Unit.
My mouse works to look up/down/left/right, however my playerMove script is not moving my FPS forward/backwards/left/right with the WASD keys.
I have set up the Input Manager to Horizontal and Vertical and it still doesn’t want to move.
What am I doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{ // adding fields for inspector
[SerializeField] private string horizontalInputName;
[SerializeField] private string verticalInputName;
[SerializeField] private float movementSpeed;
// Character controller component
private CharacterController charController;
// fields for jumping effects
[SerializeField] private AnimationCurve jumpFallOff;
[SerializeField] private float jumpMultiplier;
[SerializeField] private KeyCode jumpKey;
// boolean value
private bool isJumping;
private void Awake()
{
charController = GetComponent<CharacterController>();
}
private void update()
{
PlayerMovement();
}
// method to monitor player movements at time of action
private void PlayerMovement()
{
float horInput = Input.GetAxis(horizontalInputName) * movementSpeed;
float verInput = Input.GetAxis(verticalInputName) * movementSpeed;
Vector3 forwardMovement = transform.forward * verInput;
Vector3 rightMovement = transform.right * horInput;
charController.SimpleMove(forwardMovement + rightMovement);
//invoking jumping method
jumpInput();
}
//jumping method for player
private void jumpInput()
{
if(Input.GetKeyDown(jumpKey) && !isJumping)
{
isJumping = true;
StartCoroutine(JumpEvent());
}
}
//jumping event method
private IEnumerator JumpEvent()
{
charController.slopeLimit = 90.0f;
float airTime = 0.0f;
//do while loop for jumping event
do
{
float jumpForce = jumpFallOff.Evaluate(airTime);
charController.Move(Vector3.up * jumpForce * jumpMultiplier * Time.deltaTime);
airTime += Time.deltaTime;
yield return null;
} while (!charController.isGrounded && charController.collisionFlags != CollisionFlags.Above);
charController.slopeLimit = 45.0f;
isJumping = false;
}
}
I found my answer, one simple syntax error.
old code
public void update()
{
PlayerMovement();
}
new code
public void Update()
{
PlayerMovement();
}
fix: capital ‘U’ in Update.