- Home /
Rotate transform.forward at local x axis
Hey Guys, I'm trying to get the forward of my camera. My problem: the transform.forward of my player is not the current view direction. I have a capsule as player and and I'm rotating only the camera at the x-axis, not the player. Also, I have a spheric planet with planetary gravity. How can I calculate the forward of the camera?
My current update function:
public void Update() {
loadChunksForPlayer ();
Screen.lockCursor = true;
float rx = camera.transform.localRotation.eulerAngles.x;
Vector3 rotation = playerObj.transform.forward;
Debug.DrawRay (playerObj.transform.position, rotation, Color.green, 10);
if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) {
Ray ray = new Ray(playerObj.transform.position, rotation);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
if (hit.distance < interactionRange) {
Vector3 hitPos = hit.point + (hit.normal * (-0.5F));
hitPos = new Vector3(
Mathf.RoundToInt(hitPos.x),
Mathf.RoundToInt(hitPos.y),
Mathf.RoundToInt(hitPos.z)
);
if (Input.GetMouseButton(0)) {
sphericalDestroyVoxels(hitPos, 4);
}else {
sphericalPlaceVoxels(hitPos, 4);
}
}
}
}
}
Thanks in advance!
Comment