How to rotate locally on a single axis according to speed?

Hey,

I’m trying to make a sword that cuts objects using the Ezy-slice and I need to provide the slicing plane. How can I make my slicing plane align in one local axis with the direction you are swinging the blade?

It’s in VR, you hold the sword by the hilt and the slicing plane is offset from the hilt so it need to work if you “rotate” the hilt. Also the blade can slice in any direction that’s why I need to align the slice plane with the direction you swing, otherwise it could have just been children of the sword.

so far I have this that works with the translation, but not so much with the rotation of the hilt.

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

public class LookAtSingleAxis : MonoBehaviour
{
    [SerializeField] private float rotSpeed = 180f;
    private Vector3 _prevPos = Vector3.zero;

    void Update()
    {
        Vector3 targetDir = transform.position - _prevPos;
        float step = rotSpeed * Time.deltaTime;

        Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);
        newDir.y = 0f;

        Debug.DrawRay(transform.position, newDir * 10f, Color.red);

        transform.localRotation = Quaternion.LookRotation(newDir);
        _prevPos = transform.position;
    }
}

Thanks!

turns out it was simple after all with lookRotation

        Vector3 targetDir   = transform.position - _prevPos;

        transform.rotation = Quaternion.LookRotation(Vector3.Normalize(targetDir), transform.up);
        _prevPos = transform.position;