- Home /
movement not working,movement controller not working
followed a tutorial and got the following errors on lines 62 and 47 with "a namespace cannot directly contain members such as fields or methods
code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movementcontroller : MonoBehaviour { private float InputX, InputZ, Speed; private Camera cam; private Vector3 desiredMoveDirection;
[SerializeField] float rotationSpeed = 0.3f; [SerializeField] float allowRotation = 0.1f; [SerializeField] float movementSpeed = 1f; // Start is called before the first frame update void Start() {
characterController = GetComponent<characterController>();
cam = Camera.main;
}
// Update is called once per frame
void Update()
{
InputX = Input.GetAxis("Horizontal"); InputZ = Input.GetAxis("Vertical");
InputDecider();
MovementManager();
}
void InputDecider() { Speed = new Vector2(InputX, InputZ).sqrMagnitude;
if(Speed > allowRotation ) { RotationManager(); else { desiredMoveDirection = Vector3.zero; }
} } void RotationManager() {
var forward = cam.transform.forward; var right = cam.transform.right;
forward.y = 0; right.y = 0; forward.Normalize(); right.Normalize();
desiredMoveDirection = forward InputZ + right InputX;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection), rotationSpeed); } void movementManager() { Vector3 moveDirection = desiredMoveDirection (movementSpeed Time.deltaTime);
}
,i followed a tutorial but am getting errors on lines 47 with a name space cannot directly contain members such fields or methods,and on line 62
heres the code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movementcontroller : MonoBehaviour { private float InputX, InputZ, Speed; private Camera cam; private Vector3 desiredMoveDirection;
[SerializeField] float rotationSpeed = 0.3f; [SerializeField] float allowRotation = 0.1f; [SerializeField] float movementSpeed = 1f; // Start is called before the first frame update void Start() {
characterController = GetComponent<characterController>();
cam = Camera.main;
}
// Update is called once per frame
void Update()
{
InputX = Input.GetAxis("Horizontal"); InputZ = Input.GetAxis("Vertical");
InputDecider();
MovementManager();
}
void InputDecider() { Speed = new Vector2(InputX, InputZ).sqrMagnitude;
if(Speed > allowRotation ) { RotationManager(); else { desiredMoveDirection = Vector3.zero; }
} } void RotationManager() {
var forward = cam.transform.forward; var right = cam.transform.right;
forward.y = 0; right.y = 0; forward.Normalize(); right.Normalize();
desiredMoveDirection = forward InputZ + right InputX;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection), rotationSpeed); } void movementManager() { Vector3 moveDirection = desiredMoveDirection (movementSpeed Time.deltaTime);
}