- Home /
How can I mimic this game's camera in Unity?
Hello there,
I'm trying to mimic the camera functionality of the Knights of the Old Republic game in Unity. link:This is a link to a video for a more visual demonstration for those interested.
Essentially, what it boils down to is this:
It's a 3rd-person camera that collides with walls. (Easy enough to do with Cinemachine)
The cursor is visible and confined to the game screen. It's usually free to interact with various HUD/UI elements.
If I move the cursor to the edge of the screen, it rotates the camera along the X axis. I can also rotate the camera by holding down right-click. (Note: holding down right-click will also allow the camera to be rotated along the Y axis, but there's generally nothing to look at in either direction there, so it's not important.)
The player will move relative to the camera (e.g. the way the camera is facing is forward), but I'm fairly certain I've got that bit figured out.
Is this achievable with Cinemachine or would it be better to make a custom camera script?
Answer by MysticalSkyWhale · Nov 10, 2020 at 01:18 AM
For those interested, I think I have found a solution.
// Before any class declarations, add 'using Cinemachine;'
void Start()
{
CinemachineCore.GetInputAxis = GetAxisCustom;
}
public float GetAxisCustom(string axisName)
{
if(axisName == "Mouse X")
{
if (Input.GetKey("mouse 1"))
{
return UnityEngine.Input.GetAxis("Mouse X");
}
else
{
return 0;
}
}
else if (axisName == "Mouse Y")
{
if (Input.GetKey("mouse 1"))
{
return UnityEngine.Input.GetAxis("Mouse Y");
} else
{
return 0;
}
}
return UnityEngine.Input.GetAxis(axisName);
}
Your answer
Follow this Question
Related Questions
How to prevent camera from clipping through walls with raycasts? 0 Answers
Getting the camera to move in the direction its facing. 0 Answers
Unity 5 3D Camera scrolling script not correctly placed 0 Answers
How to make a camera Follow an Object moving in zigzag path? 1 Answer
Camera Follow (Not Exact) 1 Answer