Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

3DCamera for Fighing Game

An asset by GatitoMimoso
The page banner background of a mountain and forest
3DCamera for Fighing Game hero image

Quick Information

0 ratings
3DCamera for Fighing Game icon image
GatitoMimoso
3DCamera for Fighing Game

Camera 3D that follows Characters on the stage. This plugin supports regular movement (forward, backward and vertical), lateral movement (side steps), detects side changes (cross-ups and cross-unders). Also interpolates its translation for a smooth camera movement.The "FM" slot refers to the "Fighter Manager" node of your Characters, such "FM" node can be a "Node3D" that must have an Script attached to it; That Script must have declared 2 String variables called "current_sidePJ1" and "current_sidePJ2" so the plugin can notice you in wich side your Characters are on.These 2 String varibles are updated with the values "LEFT" or "RIGHT", giving you the signal that your Characters have changed sides.

Supported Engine Version
4.1
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
7 days ago
Git URL
Issue URL

3D-Fighting-Camera

Camera that supports 3 axis of momevement like Tekken or Soul Calibur games.
Forwards and backwards, Side Step in and out; and Cross-up/under handling.
Script and Mathematical operations involved on how this Camera works.
README Thumbnail

Keyboard movement implemented!
Yellow Cylinder controls = W,A,S,D (Cross-UP = WA or WD)
Blue Cylinder controls = I,J,K,L (Cross-UP = IJ or IL)

Mathematical explanation

Naive approach

We can just create a 2D vector between PJ1 and PJ2 (Vector_PJ), wich sense goes from PJ1 to PJ2; and then creata a perpendicular 2D Vector (Perp_Vector_PJ) that intersectes in the mid point (MidPoint_PJ) and take the angle between these vectors to assign it to the camera rotation and from there set the camera position. Problem is, Perp_Vector_PJ has fixed sense, given by Vector_PJ, causing the camera to always having the PJ1 on the Left Side and the PJ2 on the Right Side, even on cross-ups, cross-unders or just punctual collision issues where PJs pass each other trough.
README 1_naive
README 2_naive
README 3_naive
We can see that, no matter what, PJ1 is always clockwise acording to Perp_Vector_PJ.

New approach

Create a new 2D Vector parallel to Perp_Vector_PJ (Cam_Virtual_Direction), it represents the previous Perp_Vector_PJ; this new vector will be used to create another 2D Vector (Scalar_Proj) wich is the result of projecting Cam_Virtual_Direction onto Perp_Vector_PJ.

Cam_Virtual_Direction: is a vector that represents the direction of the Perp_Vector_PJ, but not its sense is not used.
Scalar_Proj: is a vector that has the direction of Perp_Vector_PJ and the sense of Cam_Virtual_Direction.

README Per_same
README Per_opposite
Even with a sudden exchange of PJs positions, the Scalar_Proj remains perpendicular to the PJs and retains its sense.

With these vectors we can take the angular difference (Ang_Diff) between Cam_Virtual_Direction and Scalar_Proj, and subtract the result to the Camera Y Rotation.
README Angluar_Difference

Consideration

Code wise, Ang_Diff is subtract to a Virtual float variable called Cam_YTarget_rot wich stores the rotation in radians that the Camera must follow.
From here we can construct a 3D Vector (Cam_Virtual_Rot) that stores the 3-Axis Rotations that the camera must follow, and another 3D Vector (Cam_Virtual_Pos) that calcualates and store the position of the camera according to the Cam_Virtual_Rot.

Asigning Rotation

New wit our camera rotated in the correct angle we can set the position in the space.
Cam_Virtual_Rot.x: desired_topdown_degree
Cam_Virtual_Rot.y: Cam_YTarget_rot
Cam_Virtual_Rot.z: desired_tilt_degreee

Asigning Position

New wit our camera rotated in the correct angle we can set the position in the space.
Cam_Virtual_Pos.x: sin(Cam_Virtual_Rot.y) * desired_distance_from_midpoint) + MidPoint_PJ.x
Cam_Virtual_Pos.y: desired_height
Cam_Virtual_Pos.z: cos(Cam_Virtual_Rot.y) * desired_distance_from_midpoint) + MidPoint_PJ.z

We can apply this values as they are, or we can interpolate them, like in the Godot project

PJs side determination

We can use cross product to determinate on wich side of the camera are the PJs.
Even when here we are using 3D Vectors, their Y Component is omited, because the Y position of PJs is irrelevant to determinate on wich side ther are on.

First we need:

CamtoCenter_vector: 3D Vector that goes from Cam_Virtual_Pos to MidPoint_PJ (Y component is set to 0.0), this is our vector reference.
PJ1Cam_vector: 3D Vector that goes from Cam_Virtual_Pos to PJ1_Pos (Y component is set to 0.0).

Then we apply Cross Product:

PJ1_crossed = CamtoCenter_vector x PJ1Cam_vector

This will give us a 3D Vector with only the Y Component, if this component is positive or 0 then PJ1 is on the Left Side of the Camera, and by discard, PJ2 is on the Right Side of the Camera.

README Producto_Vectorial_según_el_angulo_entre_vectores

This image illustrate how it works.
We can take Vector A like CamtoCenter_vector and Vector B like PJ1Cam_vector, their Y component are 0.
The Vector AxB is the cross product PJ1_crossed, its Horizontal Components (X and Z) are 0.

Camera 3D that follows Characters on the stage. This plugin supports regular movement (forward, backward and vertical), lateral movement (side steps), detects side changes (cross-ups and cross-unders). Also interpolates its translation for a smooth camera movement.

The "FM" slot refers to the "Fighter Manager" node of your Characters, such "FM" node can be a "Node3D" that must have an Script attached to it; That Script must have declared 2 String variables called "current_sidePJ1" and "current_sidePJ2" so the plugin can notice you in wich side your Characters are on.
These 2 String varibles are updated with the values "LEFT" or "RIGHT", giving you the signal that your Characters have changed sides.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
3DCamera for Fighing Game icon image
GatitoMimoso
3DCamera for Fighing Game

Camera 3D that follows Characters on the stage. This plugin supports regular movement (forward, backward and vertical), lateral movement (side steps), detects side changes (cross-ups and cross-unders). Also interpolates its translation for a smooth camera movement.The "FM" slot refers to the "Fighter Manager" node of your Characters, such "FM" node can be a "Node3D" that must have an Script attached to it; That Script must have declared 2 String variables called "current_sidePJ1" and "current_sidePJ2" so the plugin can notice you in wich side your Characters are on.These 2 String varibles are updated with the values "LEFT" or "RIGHT", giving you the signal that your Characters have changed sides.

Supported Engine Version
4.1
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
7 days ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers