Question
I’m using SpringArm3D to prevent Camera3D from going below the ground, but I can’t create the process.
I’d like to know how to use SpringArm3D while adhering to the following assumptions.
Assumptions:
Rotating Node3D (CameraPivot) rotates the child object Camera3D, which rotates the camera.Current situation: This is the image shown.
I was able to avoid the current issue of the player’s collision sticking to the player by switching the layer. I did the same for the ground, but due to the assumptions, the camera itself doesn’t move, so I can’t implement it properly.
What I’m creating:
Camera rotation processing for third-person games (e.g., Dark Souls, Mario Odyssey)
Godot Version
v4.6 C#
OS: Windows10
CameraPivot script:
using Godot;
using System;
/*
parent > CharacterBody3D : attach script
child >> CameraPivot : Nodd3D
child >>> Camera3D : Camera3D
*/
public partial class CameraController : Node3D
{
private float pitch = 0.0f;
private float yaw = 0.0f;
private float distance;
[Export] public CharacterBody3D follow;
private Tween tween;
public override void _Ready()
{
yaw = GlobalRotation.Y;
pitch = GlobalRotation.X;
}
public override void _Input(InputEvent @event)
{
}
public override void _Process(double delta)
{
float deadZone = 0.1f;
float rightX = Input.GetJoyAxis(0,JoyAxis.RightX);
float rightY = Input.GetJoyAxis(0,JoyAxis.RightY);
Vector2 rightAxis = new Vector2(rightX,rightY);
if(Math.Abs(rightAxis.X) > deadZone)
{
float newLength = (Math.Abs(rightAxis.X) - deadZone) / (1.0f - deadZone);
rightAxis.X = newLength * Math.Sign(rightAxis.X);
}
if(Math.Abs(rightAxis.Y) > deadZone)
{
float newLength = (Math.Abs(rightAxis.Y) - deadZone) / (1.0f - deadZone);
rightAxis.Y = newLength * Math.Sign(rightAxis.Y);
}
//デッドゾーン
if(Math.Abs(rightAxis.Length()) > deadZone)
{
pitch -= rightAxis.Y * 0.10f;
pitch = Mathf.Clamp(pitch, -Mathf.Pi / 2, Mathf.Pi / 2);
yaw -= rightAxis.X * 0.10f;
GlobalRotation = new Vector3(pitch,yaw,0);
}
GlobalPosition = GlobalPosition.Lerp(follow.GlobalPosition,(float)(1.0 - Mathf.Exp(-10 * delta)));
}
public override void _PhysicsProcess(double delta)
{
}
}
