gd: setup a target and a simple dash to target
This commit is contained in:
@ -26,6 +26,7 @@ shadow_enabled = true
|
|||||||
|
|
||||||
[node name="Greybox" type="CSGCombiner3D" parent="."]
|
[node name="Greybox" type="CSGCombiner3D" parent="."]
|
||||||
use_collision = true
|
use_collision = true
|
||||||
|
collision_layer = 3
|
||||||
|
|
||||||
[node name="CSGBox3D" type="CSGBox3D" parent="Greybox"]
|
[node name="CSGBox3D" type="CSGBox3D" parent="Greybox"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.09619, -0.472656, -0.958893)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.09619, -0.472656, -0.958893)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=25 format=3 uid="uid://bei4nhkf8lwdo"]
|
[gd_scene load_steps=27 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||||
[ext_resource type="Material" uid="uid://dtq8i1ka1f2pn" path="res://player_controller/Assets/Materials/Health/CameraVignette.tres" id="2_6hee7"]
|
[ext_resource type="Material" uid="uid://dtq8i1ka1f2pn" path="res://player_controller/Assets/Materials/Health/CameraVignette.tres" id="2_6hee7"]
|
||||||
@ -30,6 +30,10 @@ shader_parameter/blur = 0.0
|
|||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_qu4wy"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_qu4wy"]
|
||||||
height = 1.5
|
height = 1.5
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id="SphereMesh_qu4wy"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v31n3"]
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_vcu7l"]
|
[sub_resource type="Animation" id="Animation_vcu7l"]
|
||||||
length = 0.001
|
length = 0.001
|
||||||
tracks/0/type = "bezier"
|
tracks/0/type = "bezier"
|
||||||
@ -215,8 +219,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.68, 0)
|
|||||||
shape = SubResource("CapsuleShape3D_qu4wy")
|
shape = SubResource("CapsuleShape3D_qu4wy")
|
||||||
target_position = Vector3(0, 0, -20)
|
target_position = Vector3(0, 0, -20)
|
||||||
max_results = 1
|
max_results = 1
|
||||||
|
collision_mask = 2
|
||||||
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
|
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
|
||||||
|
|
||||||
|
[node name="DashTarget" type="MeshInstance3D" parent="DashSystem"]
|
||||||
|
mesh = SubResource("SphereMesh_qu4wy")
|
||||||
|
surface_material_override/0 = SubResource("StandardMaterial3D_v31n3")
|
||||||
|
|
||||||
[node name="StairsSystem" type="Node3D" parent="."]
|
[node name="StairsSystem" type="Node3D" parent="."]
|
||||||
script = ExtResource("7_bmt5a")
|
script = ExtResource("7_bmt5a")
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ using RustyOptions;
|
|||||||
|
|
||||||
namespace PolarBears.PlayerControllerAddon;
|
namespace PolarBears.PlayerControllerAddon;
|
||||||
|
|
||||||
|
public record DashLocation(Result<Vector3, string> Result, bool HasHit);
|
||||||
|
|
||||||
public partial class DashSystem: Node3D
|
public partial class DashSystem: Node3D
|
||||||
{
|
{
|
||||||
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
||||||
@ -11,25 +13,48 @@ public partial class DashSystem: Node3D
|
|||||||
private Node3D _head;
|
private Node3D _head;
|
||||||
private ShapeCast3D _dashCast3D;
|
private ShapeCast3D _dashCast3D;
|
||||||
private Camera3D _camera;
|
private Camera3D _camera;
|
||||||
|
private MeshInstance3D _dashTarget;
|
||||||
|
|
||||||
public void Init(Node3D head, Camera3D camera)
|
public void Init(Node3D head, Camera3D camera)
|
||||||
{
|
{
|
||||||
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
|
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
|
||||||
_head = head;
|
_head = head;
|
||||||
_camera = camera;
|
_camera = camera;
|
||||||
|
_dashTarget = GetNode<MeshInstance3D>("DashTarget");
|
||||||
|
_dashTarget.SetVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DashLocation ComputeDashLocation()
|
||||||
|
{
|
||||||
|
var dashLocation = _dashCast3D.IsColliding()
|
||||||
|
? _dashCast3D.GetCollisionPoint(0)
|
||||||
|
: _dashCast3D.ToGlobal(_dashCast3D.TargetPosition);
|
||||||
|
return new DashLocation(Result.Ok(dashLocation), _dashCast3D.IsColliding());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<Vector3, string> PrepareDash()
|
public Result<Vector3, string> PrepareDash()
|
||||||
{
|
{
|
||||||
|
_dashTarget.SetVisible(false);
|
||||||
|
|
||||||
_dashCast3D.SetRotation(new Vector3(
|
_dashCast3D.SetRotation(new Vector3(
|
||||||
_camera.Rotation.X,
|
_camera.Rotation.X,
|
||||||
_head.Rotation.Y,
|
_head.Rotation.Y,
|
||||||
_camera.Rotation.Z));
|
_camera.Rotation.Z));
|
||||||
|
|
||||||
var dashLocation = _dashCast3D.IsColliding()
|
var (result, hasHit) = ComputeDashLocation();
|
||||||
? _dashCast3D.GetCollisionPoint(0)
|
|
||||||
: _dashCast3D.GetTargetPosition();
|
var targetColor = hasHit ? new Color(0.2f, 0.2f, 1f) : new Color(1f, 1f, 1f);
|
||||||
|
var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0);
|
||||||
|
targetMaterial.AlbedoColor = targetColor;
|
||||||
|
|
||||||
|
_dashTarget.SetVisible(true);
|
||||||
|
_dashTarget.SetGlobalPosition(result.Unwrap());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return Result.Ok(dashLocation);
|
public void Dash()
|
||||||
|
{
|
||||||
|
_dashTarget.SetVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
|
|
||||||
private bool _canDoubleJump = true;
|
private bool _canDoubleJump = true;
|
||||||
private bool _movementEnabled = true;
|
private bool _movementEnabled = true;
|
||||||
|
private Vector3 _dashLocation = Vector3.Zero;
|
||||||
|
|
||||||
private float _currentSpeed;
|
private float _currentSpeed;
|
||||||
|
|
||||||
@ -138,9 +139,30 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
_movementEnabled = true;
|
_movementEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TweenToLocation(Vector3 location, float duration)
|
||||||
|
{
|
||||||
|
Tween tween = GetTree().CreateTween();
|
||||||
|
var callback = new Callable(this, MethodName.EnableMovement);
|
||||||
|
|
||||||
|
tween.TweenProperty(this, "position", location, duration);
|
||||||
|
tween.TweenCallback(callback);
|
||||||
|
|
||||||
|
DisableMovement();
|
||||||
|
tween.Play();
|
||||||
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var dashLocation = DashSystem.PrepareDash().Unwrap();
|
if (Input.IsActionPressed("aim_dash"))
|
||||||
|
{
|
||||||
|
_dashLocation = DashSystem.PrepareDash().Unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.IsActionJustReleased("aim_dash"))
|
||||||
|
{
|
||||||
|
DashSystem.Dash();
|
||||||
|
TweenToLocation(_dashLocation, 0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
var mantleLocationResult = MantleSystem.CheckWallInFront();
|
var mantleLocationResult = MantleSystem.CheckWallInFront();
|
||||||
if (isOnFloorCustom())
|
if (isOnFloorCustom())
|
||||||
@ -169,15 +191,8 @@ public partial class PlayerController : CharacterBody3D
|
|||||||
{
|
{
|
||||||
if (mantleLocationResult.IsOk(out var mantleLocation))
|
if (mantleLocationResult.IsOk(out var mantleLocation))
|
||||||
{
|
{
|
||||||
Tween tween = GetTree().CreateTween();
|
|
||||||
var duration = 0.1f * mantleLocation.DistanceTo(Position);
|
var duration = 0.1f * mantleLocation.DistanceTo(Position);
|
||||||
var callback = new Callable(this, MethodName.EnableMovement);
|
TweenToLocation(mantleLocation, duration);
|
||||||
|
|
||||||
tween.TweenProperty(this, "position", mantleLocation, duration);
|
|
||||||
tween.TweenCallback(callback);
|
|
||||||
|
|
||||||
DisableMovement();
|
|
||||||
tween.Play();
|
|
||||||
}
|
}
|
||||||
else if (isOnFloorCustom())
|
else if (isOnFloorCustom())
|
||||||
{
|
{
|
||||||
|
@ -85,6 +85,11 @@ look_down={
|
|||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
aim_dash={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user