Hello, i stumbled upon this movement script that works with a touchscreen joystick, but i need help integrating the speed control because is normally moves fairly slow, that variable is there i just don’t know how to make it effect the movement. I would greatly appreciate any help, this has had me stumped for a while.
using UnityEngine;
using CnControls;
[RequireComponent(typeof(CharacterController))]
public class JoystickController : MonoBehaviour
{
public float MovementSpeed = 50f;
private Transform _mainCameraTransform;
private Transform _transform;
private CharacterController _characterController;
private void OnEnable()
{
_mainCameraTransform = Camera.main.GetComponent<Transform>();
_characterController = GetComponent<CharacterController>();
_transform = GetComponent<Transform>();
}
public void Update()
{
// Just use CnInputManager. instead of Input. and you're good to go
var inputVector = new Vector3(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
Vector3 movementVector = Vector3.zero;
// If we have some input
if (inputVector.sqrMagnitude > 0.1f)
{
movementVector = _mainCameraTransform.TransformDirection(inputVector);
movementVector.y = 0f;
movementVector.Normalize();
_transform.forward = movementVector;
}
movementVector += Physics.gravity;
_characterController.Move(movementVector * Time.deltaTime);
}
}