using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveHand : MonoBehaviour
{
    [SerializeField] private float speed;

    private float translation_z;
    private float mouseX;
    private float mouseY;

    // Vectors containing the start position and orientation of the hand (for reset)
    private Vector3 start_position;
    private Vector3 start_orientation;

    // Awake is called when the object is instantiated, together with MonoBehaviour
    void Awake()
    {
        start_position = transform.position;
        start_orientation = transform.eulerAngles;
    }

    // Update is called once per frame
    void Update()
    {
        // Get mouse movement for X and Y axes
        mouseX = Input.GetAxis("Mouse X") * speed * Time.deltaTime;
        mouseY = Input.GetAxis("Mouse Y") * speed * Time.deltaTime;

        // Only get keyboard input for Z movement
        translation_z = Input.GetAxis("Vertical") * speed * Time.deltaTime;

        // Move the object along the X and Y based on mouse movement
        this.gameObject.transform.Translate(mouseX, 0, mouseY);

        // Move the object along the Z direction based on keyboard input
        this.gameObject.transform.Translate(0, 0, -translation_z);

        // Allow object to move up and down with Q and E keys
        if (Input.GetKey("q"))
        {
            this.gameObject.transform.position += new Vector3(0, 1, 0) * Time.deltaTime * speed;
        }
        if (Input.GetKey("e"))
        {
            this.gameObject.transform.position -= new Vector3(0, 1, 0) * Time.deltaTime * speed;
        }

        // Reset the position and orientation of the hand with their initial ones
        if (Input.GetKey("r"))
        {
            transform.position = start_position;
            transform.eulerAngles = start_orientation;
        }
    }
}
