I’m not sure what is going on, but because my player object was already pointing so that left and right movement was on the Z-axis. I had already done a large portion of animation and decided to try to do the Vector3 movement using a zOffset. This created weird behaviour where object position wasn’t updating but eventually I got it to move with left and right inputs.
Now whenever I try to do y-axis movement in the same manner adding ‘+=’ transform.localPosition , the player object vanishes out of bounds immediately.
If I’m getting left and right movement using '+= ’ then up and down movement doesn’t register.
Any ideas what’s going on here? Thanks
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float controlSpeed = 100f;
Vector3 movement;
// Update is called once per frame
void Update()
{
ProcessTranslationZ();
ProcessTranslationY();
}
void ProcessTranslationZ()
{
float xOffset = movement.x * controlSpeed * Time.deltaTime;
transform.localPosition += new Vector3(0f, 0f, -(transform.localPosition.x + xOffset));
}
void ProcessTranslationY()
{
float yOffset = movement.y * controlSpeed * Time.deltaTime;
transform.localPosition = new Vector3(0f, transform.localPosition.y + yOffset, 0f);
}
public void OnMovement(InputValue value)
{
Debug.Log(movement);
movement = value.Get<Vector2>();
}
}