So my player has movement based on camera direction. All works fine.
I want to be able to push and pull boxes around. So my script is:
public void BoxInteract()
{
if (Input.GetMouseButton(0))
{
hit.collider.transform.parent = this.transform;
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(0f, 0f, vertical).normalized;
transform.Translate(direction * Time.deltaTime, Space.Self);
}
Works fine, I can push forward and pull -forward. But, if my player is slightly rotated, the direction will be rotated as well.
I want to only push and pull on fixed angles (0º, 90º, 180º, -90º). How can I do that?
I tried making the player children of the box, it almost worked, the box moved correct, but then I can only move forward and -forward relative to the box rotation, I need the move relative to the player’s forward and -forward.