Camera
parent
0e2d4f3636
commit
74fabb1b9a
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace DRPGActionGame.Player;
|
||||
|
||||
public partial class CameraController : Node3D {
|
||||
[Export] private float sensitivity = 5f;
|
||||
[Export] private SpringArm3D springArm3D;
|
||||
|
||||
private const float maxXRot = .25f;
|
||||
private const float maxZoom = 2f;
|
||||
private const float minZoom = 10f;
|
||||
|
||||
public override void _Ready() => Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
|
||||
// public override void _Process(double delta) => GlobalPosition = GetParent<Node3D>().GlobalPosition;
|
||||
|
||||
public override void _Input(InputEvent @event) {
|
||||
switch (@event) {
|
||||
case InputEventMouseMotion inputEventMouseMotion: {
|
||||
float xRot = Mathf.Clamp(Rotation.X - inputEventMouseMotion.Relative.Y / 1000 * sensitivity, -maxXRot, +maxXRot);
|
||||
float yRot = Rotation.Y - inputEventMouseMotion.Relative.X / 1000 * sensitivity;
|
||||
Rotation = new(xRot, yRot, 0);
|
||||
break;
|
||||
}
|
||||
case InputEventMouseButton inputEventMouseButton: {
|
||||
if (inputEventMouseButton.ButtonIndex == MouseButton.WheelDown) {
|
||||
if (springArm3D.SpringLength < minZoom)
|
||||
springArm3D.SpringLength += 0.1f;
|
||||
}
|
||||
else if (inputEventMouseButton.ButtonIndex == MouseButton.WheelUp) {
|
||||
if (springArm3D.SpringLength > maxZoom)
|
||||
springArm3D.SpringLength -= 0.1f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
|
||||
namespace DRPGActionGame.Player;
|
||||
|
||||
public partial class Player2 : CharacterBody3D
|
||||
{
|
||||
private const float SPEED = 5.0f;
|
||||
private const float JUMP_VELOCITY = 4.5f;
|
||||
|
||||
// Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
private float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
|
||||
|
||||
[Export] private AnimationPlayer animationPlayer;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
// Add the gravity.
|
||||
if (!IsOnFloor())
|
||||
velocity.Y -= gravity * (float)delta;
|
||||
|
||||
// Handle Jump.
|
||||
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
|
||||
velocity.Y = JUMP_VELOCITY;
|
||||
|
||||
// Get the input direction and handle the movement/deceleration.
|
||||
// As good practice, you should replace UI actions with custom gameplay actions.
|
||||
Vector2 inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
|
||||
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
animationPlayer.Play("Walking_A");
|
||||
velocity.X = direction.X * SPEED;
|
||||
velocity.Z = direction.Z * SPEED;
|
||||
}
|
||||
else {
|
||||
animationPlayer.Play("Idle");
|
||||
velocity.X = Mathf.MoveToward(Velocity.X, 0, SPEED);
|
||||
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, SPEED);
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue