I have a 1st person and my sword is supposed like the guns you see in fpses but I’ve tried to add an offset to the sword position becuase all I see is the sword’s pommel and guard(I don’t want to change the pivot point of the sword because I want to add animations to it) but the offset only changes the point where the sword rotates around. What should I do so that it rotates around the player but allows me to add a offset so my sword’s position is offset but not the point of rotation
my camera script
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseCameraScript : MonoBehaviour
{
CursorLockMode lockerd = CursorLockMode.Locked;
void Start()
{
Cursor.lockState = lockerd;
}
//^ just locks the mouse
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
public float length;
public Vector3 SwordPos;
public Transform Sword;
public Vector3 SwordOffset;
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(transform.position, Camera.main.transform.forward * length, Color.black);
//v This makes the point where the sword rotates around
SwordPos = ray.origin + (ray.direction * length);
SwordPos = ray.GetPoint(length);
//^
Sword.position = SwordPos;
Debug.Log(ray.origin);
//^Main problem area(there might be a problem below but idk)
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}