Help converting controls to new input system...

I’m new here so apologies if this is not the correct place or process… I tried.

I’m trying to convert an old controller to the new input system and I am just not getting it.

I am trying to read the value from a new 1d axis similar to the old “Horizontal” axis from the old input manager. I am able to read the axis value as a float which appears to be returning the type of value used in my old controller but won’t execute and no compiler errors.

Thanks!

public class TouchController : MonoBehaviour
{
Rigidbody playershipRB;
float verticalMove;
float speedMult = 1;
public Vector3 playerPosition;
private CharacterController controller;
private float playerSpeed = 5.0f;
private Actions playerInput;
 
private void Awake()
    {
        playerInput = new Actions();
        controller = GetComponent<CharacterController>();
    }
  
private void OnEnable()
    {
        playerInput.Enable();
    }
 
private void OnDisable()
    {
        playerInput.Disable();
    }
  
void Start()
    {
     
    }
  
void Update()
    {
        playerPosition = transform.position;
      
        verticalMove = playerInput.Player.VerticalMove.ReadValue<float>();
     
void FixedUpdate()
    {
        playershipRB.AddForce(playershipRB.transform.TransformDirection(Vector3.forward) * verticalMove * speedMult, ForceMode.VelocityChange);
        Debug.Log("move");
      
    }
}

well, there is nothing specifically obviously wrong, you should be able to debug the value of verticalMove to confirm that that is changing

It’s changing alright :slight_smile:

I must have something else in the project conflicting who knows thank you.

This line is not executing:

playershipRB.AddForce(playershipRB.transform.TransformDirection(Vector3.forward) * verticalMove * speedMult, ForceMode.VelocityChange);

well Id expect playershipRB.transform.forward * … but check the value of verticalMove * speedMult it may not result in much of a value so check you dont need more umpf behind it…

Thank you I apologize for wasting your time… I never initialized my rigid body:

playershipRB = GetComponent<Rigidbody>();

then you would have had a null reference error you failed to mention

1 Like

It’s very unusual to have both a rigidbody and a character controller on the same object. It could prove to be problematic for you.

1 Like