Referencing a camera's orientation to affect another objects axes for control
Sorry if the title was confusing. I'm working on a project where a sphere is using gravity (at the moment) to roll on a table that pivots on its x and z axis. I have a camera that will orbit the sphere to provide the player with better visibility. The table is controlled by manipulating the rotation of the x and z axis. The problems begin when the camera moves to another angle, yet the x and z axis remain the same on the table. Controls get really wonky at that point as the player has to adjust. I'd like to somehow read the real-time x and z axis rotation of the camera for the controls of the table, if that's even possible. I've included the scripts for the table "player" and for the camera. Any help would be greatly appreciated. :-) Player.cs
void Update() { var gamepad = Gamepad.current; if (gamepad == null) return;
else
{
Vector3 move = gamepad.leftStick.ReadValue();
_yaw += -1 * (_tiltVelocityX * move.x);
_pitch -= -1 * (_tiltVelocityY * move.y);
transform.eulerAngles = new Vector3(_pitch, 0.0f, _yaw);
}
}
} FollowCamera.cs
{ [SerializeField] GameObject player; [SerializeField] float OrbitDegrees = 100f;
Vector3 _offset;
void Start()
{
_offset = (transform.position - player.transform.position);
}
void Update()
{
var gamepad = Gamepad.current;
if (gamepad == null)
return;
else
CameraOrbitControl(gamepad);
}
void CameraOrbitControl(Gamepad gamepad)
{
Vector3 move = gamepad.rightStick.ReadValue();
transform.RotateAround(player.transform.position, Vector3.up, OrbitDegrees * move.x);
}
-Chaun
I suppose another way to put it is... Can you reference one objects directional orientation and pass it on to a second object without physically moving the second? The first objects actual orientation is ever changing while the second never changes. Thanks again..
-Chaun
I noticed an answer to another question regarding orientation using:
var cameraRelativeFwd = Camera.current.transform.TransformDirection(Vector3.forward);
I actually placed "current" in lieu of mainCamera as I am using a virtual camera through Cinemachine. I'm not sure where to go from here if this will orient my table based on the camera view. I don't want the table to do anything other than pivot using the camera's local orientation. Hope I'm describing this accurately. I'm pretty new to program$$anonymous$$g so please forgive my neewbness. Lol
-Chaun