For months I’ve been struggling trying to create a 3D Camera system that works like either Tekken or Soul Calibur. My main issue to getting the camera to rotate around the camera’s pivot point while still keeping both players within the camera. Tried getting a reference to difference of both player’s positions to use that as an offset and used a Vector3.Cross to get perpendicular to camera’s pivot point but that didn’t work. I tried using a LookAt function to focus on the Y position of the Camera Pivot, that didn’t work. I tried using RotateY and other methods and that didn’t work. Can someone explain what am I doing wrong? Cause when I write something similar in Unity I was able to get a result that I wanted. Thanks for the help.
For reference here is some comment snippets of the function I was trying to work on.
public void RotateCamera() { //Allows the Camera to rotate around both players.
for rotating around the player you might want to use something like this
public void SetCameraRotation(float newRotationAngleRad)
{
cameraPivot.Rotation = Vector3.Zero;
cameraPivot.RotateY(newRotationAngleRad);
}
this should work until the distance between the players changes. You probably want to have the camera zoom/distance in a way to always keep both characters visible.
For this you might want to check out the kidscancode tutorial about multitarget cameras
When I’m using the function RotateY, is that supposed to automatically add the rotation when one of my players move? Cause the newRotationAngleRad only changes once and not dynamically. I’m calling this function in the _Process function if that helps.
Edit: I’ve been experimenting with the Angle and using my player’s position for the angle is getting me close but it’s not what I’m looking for.
The code I’ve described can be used if you always pass the actual rotation (not a rotation change).
So yes, RotateY rotates the camera relative to the current position.
But this line:
cameraPivot.Rotation = Vector3.Zero;
resets the rotation.
If you want to constantly rotate the camera by the same amount, remove that line.
So if you want to rotate by a fixed amout, e.g. 10° per second, you can do something like this:
public override void _Process(double delta)
{
ChangeCameraRotation((float)(Mathf.DegToRad(10) * delta))
}
public void ChangeCameraRotation(float rotationAngleRadChange)
{
cameraPivot.RotateY(rotationAngleRadChange);
}
From how this is being written logically, it should works since it’s just modifying the Y-axis’s rotation over time but it still doesn’t work for some reason. Here is a video demo of what I’m seeing.
I might have misunderstood if you want the camera to spin around constantly or not.
So what you actually want is probably to align the camera so that it is always facing the sides of both players. Because you already do a look_at on both players so that they face each other, I think you only need to find out the current player rotation of one player (around y) and rotate it by 90 degree.
Since we are passing a target rotation instead of a relative change, lets use this snippet for setting the rotation:
There’s a Unity-Cinemachine-like plugin named phantom-camera. You can refer to the group follow mode logic in the plugin or just use the plugin in your project. It’s written in GDScript but interop between C# and GDScript is simple enough.