hey i've followed the unity roll ball tutorial but my OnMove function seems to be unused then my player won't move in unity
this is my code:
using UnityEngine;
using UnityEngine.InputSystem;
public class playerController : MonoBehaviour
{
private Rigidbody rb;
private float moveX;
private float moveY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>(); //ref to player's rigidbody
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
moveX = movementVector.x;
moveY = movementVector.y;
}
private void FixedUpdate()
{
Vector3 movement = new Vector3(moveX, 0.0f, moveY);
rb.AddForce(movement);
}
}
unity windows
hey i've followed the unity roll ball tutorial but my OnMove function seems to be unused then my player won't move in unity
this is my code:
using UnityEngine;
using UnityEngine.InputSystem;
public class playerController : MonoBehaviour
{
private Rigidbody rb;
private float moveX;
private float moveY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>(); //ref to player's rigidbody
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
moveX = movementVector.x;
moveY = movementVector.y;
}
private void FixedUpdate()
{
Vector3 movement = new Vector3(moveX, 0.0f, moveY);
rb.AddForce(movement);
}
}
unity windows
Share Improve this question edited Feb 6 at 6:19 Ando Razafy asked Feb 6 at 4:24 Ando RazafyAndo Razafy 112 bronze badges 11 | Show 6 more comments1 Answer
Reset to default 0Start by assigning your input action asset in the player input component.
At the bottom (above the buttons Open Input Settings
and Open Input Debugger
) there is a list of the function names that will be called.
In my case I have actions Mouse1
and Mouse4
, but in the list they are called OnMouse1
and OnMouse4
.
private void OnMouse1(UnityEngine.InputSystem.InputValue obj)
{
Debug.Log($"Mouse 1");
}
private void OnMouse4(UnityEngine.InputSystem.InputValue obj)
{
Debug.Log($"Mouse 4");
}
Rename your functions in the code if needed, and it should work!
OnMove
function does not seem to be unused. It is unused. It cannot be used. This function is private and not called anywhere. This way, is cannot be used and makes no sense. Is that you wanted to understand? You did not ask a question. – Sergey A Kryukov Commented Feb 6 at 4:39PlayerInput
component which can be set to useSendMessage
and invoke the method via Unity's messaging system which can useprivate
methods – derHugo Commented Feb 6 at 5:40PlayerInput
component? Can you also show us your InputActions? – derHugo Commented Feb 6 at 5:40Start
,FixedUpdate
and many more are discovered on compile time and hooked directly into the underlyingc++
engine player loop callbacks. It's not really something we chose .. it's how Unity does it – derHugo Commented Feb 6 at 7:58