gd,fix: player won't go through thin platforms from underneath, added a small cooldown to dash actions, remapped inputs a bit for gamefeel

This commit is contained in:
2025-06-20 11:55:19 +02:00
parent 826eaac10c
commit 3a761fd0bd
9 changed files with 151 additions and 48 deletions

View File

@ -15,6 +15,7 @@ public partial class DashSystem: Node3D
private Node3D _head;
private ShapeCast3D _dashCast3D;
private ShapeCast3D _playerCast3D;
private Camera3D _camera;
private TweenQueueSystem _tweenQueueSystem;
private Vector3 _dashDirection = Vector3.Zero;
@ -34,6 +35,8 @@ public partial class DashSystem: Node3D
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem)
{
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
_playerCast3D = GetNode<ShapeCast3D>("PlayerShapeCast3D");
_head = head;
_camera = camera;
_tweenQueueSystem = tweenQueueSystem;
@ -53,9 +56,37 @@ public partial class DashSystem: Node3D
}
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
var collisionShape = (SphereShape3D) _dashCast3D.GetShape();
var centerSphereLocation = collisionPoint + collisionNormal * 0.2f;
return new DashComputationRecord(true, centerSphereLocation, collisionPoint, collisionNormal);
// var playerEndLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal);
var fraction = _dashCast3D.GetClosestCollisionSafeFraction();
var globalSweepPath = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition) - _dashCast3D.GlobalPosition;
var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction;
var maxPushDownDistance = 0.9f;
var correctionProportion = (float)Mathf.Remap(collisionNormal.Y, -0.5, -1, 0, 1);
var proportion = (float) Mathf.Remap(_dashCast3D.GlobalRotation.X, 0, 1.57, 0, 1);
locationAlongPath += collisionNormal * maxPushDownDistance * proportion * correctionProportion;
var otherLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal);
return new DashComputationRecord(true, locationAlongPath, collisionPoint, collisionNormal);
}
public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null)
{
if (!normal.HasValue)
return location;
var castStartLocation = location + 2 * normal.Value;
var castEndLocation = -2 * normal.Value;
_playerCast3D.SetGlobalPosition(castStartLocation);
_playerCast3D.SetTargetPosition(castEndLocation);
if (!_playerCast3D.IsColliding())
return castEndLocation;
var fraction = _playerCast3D.GetClosestCollisionSafeFraction();
var locationAlongPath = castEndLocation * fraction;
return castStartLocation + locationAlongPath;
}
public void PrepareDash()

View File

@ -1,11 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://cqduhd4opgwvm"]
[ext_resource type="Script" uid="uid://dwoppk8j5fxeg" path="res://systems/dash/DashSystem.cs" id="1_hwig2"]
[ext_resource type="Shape3D" uid="uid://keseacdcooot" path="res://player_controller/resources/PlayerShape.tres" id="2_jngg2"]
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="2_pff7b"]
[sub_resource type="SphereShape3D" id="SphereShape3D_qu4wy"]
radius = 0.2
[sub_resource type="SphereMesh" id="SphereMesh_qu4wy"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v31n3"]
@ -13,9 +11,15 @@ radius = 0.2
[node name="DashSystem" type="Node3D"]
script = ExtResource("1_hwig2")
[node name="PlayerShapeCast3D" type="ShapeCast3D" parent="."]
shape = ExtResource("2_jngg2")
target_position = Vector3(0, 0, 0)
collision_mask = 2
debug_shape_custom_color = Color(0.863327, 0.636844, 0, 1)
[node name="DashCast3D" type="ShapeCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.68, 0)
shape = SubResource("SphereShape3D_qu4wy")
shape = ExtResource("2_jngg2")
target_position = Vector3(0, 0, -12)
max_results = 1
collision_mask = 2

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="GUIDEAction" load_steps=2 format=3 uid="uid://c3e0ivgaxrsyb"]
[ext_resource type="Script" uid="uid://cluhc11vixkf1" path="res://addons/guide/guide_action.gd" id="1_gn1pi"]
[resource]
script = ExtResource("1_gn1pi")
name = &""
action_value_type = 0
block_lower_priority_actions = true
emit_as_godot_actions = false
is_remappable = false
display_name = ""
display_category = ""
metadata/_custom_type_script = "uid://cluhc11vixkf1"

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=65 format=3 uid="uid://bl5crtu1gkrtr"]
[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=71 format=3 uid="uid://bl5crtu1gkrtr"]
[ext_resource type="Script" uid="uid://cpplm41b5bt6m" path="res://addons/guide/guide_action_mapping.gd" id="1_qmhk6"]
[ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/base_mode/move.tres" id="2_g6bbx"]
@ -14,7 +14,9 @@
[ext_resource type="Script" uid="uid://ckggy40lm0vjc" path="res://addons/guide/modifiers/guide_modifier_negate.gd" id="12_kxb2c"]
[ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/base_mode/rotate_floorplane.tres" id="13_v2ywt"]
[ext_resource type="Resource" uid="uid://dgfww8118d8gj" path="res://systems/inputs/base_mode/aim.tres" id="14_vtk18"]
[ext_resource type="Resource" uid="uid://c3e0ivgaxrsyb" path="res://systems/inputs/base_mode/aim_down.tres" id="14_yp12v"]
[ext_resource type="Script" uid="uid://b52rqq28tuqpg" path="res://addons/guide/triggers/guide_trigger_pressed.gd" id="15_fykw6"]
[ext_resource type="Script" uid="uid://b4cdrn4paoj3i" path="res://addons/guide/triggers/guide_trigger_down.gd" id="15_g6bbx"]
[ext_resource type="Resource" uid="uid://j1o5ud0plk4" path="res://systems/inputs/base_mode/aim_release.tres" id="16_rvpjj"]
[ext_resource type="Script" uid="uid://biiggjw6tv4uq" path="res://addons/guide/triggers/guide_trigger_released.gd" id="17_s8kjn"]
[ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/base_mode/aim_cancel.tres" id="18_vibkn"]
@ -53,7 +55,7 @@ triggers = Array[ExtResource("8_2tfaw")]([])
script = ExtResource("1_qmhk6")
action = ExtResource("2_g6bbx")
input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_1igva")])
metadata/_guide_input_mappings_collapsed = false
metadata/_guide_input_mappings_collapsed = true
[sub_resource type="Resource" id="Resource_05q5j"]
script = ExtResource("10_cvxqo")
@ -134,7 +136,7 @@ script = ExtResource("10_cvxqo")
axis = 4
joy_index = -1
[sub_resource type="Resource" id="Resource_ib0yi"]
[sub_resource type="Resource" id="Resource_li5ak"]
script = ExtResource("15_fykw6")
actuation_threshold = 0.5
@ -146,7 +148,8 @@ display_name = ""
display_category = ""
input = SubResource("Resource_ufouq")
modifiers = Array[ExtResource("5_0qat1")]([])
triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_ib0yi")])
triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_li5ak")])
metadata/_guide_triggers_collapsed = false
[sub_resource type="Resource" id="Resource_0hmrk"]
script = ExtResource("1_qmhk6")
@ -154,6 +157,30 @@ action = ExtResource("14_vtk18")
input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_qbthx")])
metadata/_guide_input_mappings_collapsed = false
[sub_resource type="Resource" id="Resource_si4d4"]
script = ExtResource("10_cvxqo")
axis = 4
joy_index = -1
[sub_resource type="Resource" id="Resource_2tfaw"]
script = ExtResource("15_g6bbx")
actuation_threshold = 0.5
[sub_resource type="Resource" id="Resource_q86qg"]
script = ExtResource("3_yp12v")
override_action_settings = false
is_remappable = false
display_name = ""
display_category = ""
input = SubResource("Resource_si4d4")
modifiers = Array[ExtResource("5_0qat1")]([])
triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_2tfaw")])
[sub_resource type="Resource" id="Resource_cvxqo"]
script = ExtResource("1_qmhk6")
action = ExtResource("14_yp12v")
input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_q86qg")])
[sub_resource type="Resource" id="Resource_cqc4k"]
script = ExtResource("10_cvxqo")
axis = 4
@ -177,7 +204,7 @@ triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_vanwy")])
script = ExtResource("1_qmhk6")
action = ExtResource("16_rvpjj")
input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_bkx7d")])
metadata/_guide_input_mappings_collapsed = true
metadata/_guide_input_mappings_collapsed = false
[sub_resource type="Resource" id="Resource_lfx76"]
script = ExtResource("19_qkgmj")
@ -280,5 +307,5 @@ metadata/_guide_input_mappings_collapsed = false
[resource]
script = ExtResource("23_llfhp")
display_name = ""
mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_0hmrk"), SubResource("Resource_iihs4"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw"), SubResource("Resource_0qat1")])
mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_0hmrk"), SubResource("Resource_cvxqo"), SubResource("Resource_iihs4"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw"), SubResource("Resource_0qat1")])
metadata/_custom_type_script = "uid://dsa1dnifd6w32"

View File

@ -11,6 +11,7 @@ class_name InputController
@export_group("Trigger actions")
@export var aim_pressed:GUIDEAction
@export var aim_down:GUIDEAction
@export var aim_released:GUIDEAction
@export var aim_canceled:GUIDEAction
@export var jump:GUIDEAction
@ -22,6 +23,7 @@ signal input_rotate_y(value: float)
signal input_rotate_floorplane(value: float)
signal input_aim_pressed
signal input_aim_down
signal input_aim_released
signal input_aim_canceled
signal input_jump
@ -32,6 +34,7 @@ func _ready() -> void:
GUIDE.enable_mapping_context(base_mode)
aim_pressed.triggered.connect(on_input_aim_pressed)
aim_down.triggered.connect(on_input_aim_down)
aim_released.triggered.connect(on_input_aim_released)
aim_canceled.triggered.connect(on_input_aim_canceled)
jump.triggered.connect(on_input_jump)
@ -50,6 +53,9 @@ func on_input_jump():
func on_input_aim_pressed():
input_aim_pressed.emit()
func on_input_aim_down():
input_aim_down.emit()
func on_input_aim_released():
input_aim_released.emit()

View File

@ -1,3 +1,4 @@
using System;
using Godot;
using GodotStateCharts;
@ -23,9 +24,8 @@ public partial class WeaponSystem : RigidBody3D
private Transform3D _startTransform;
private Vector3 _throwDirection;
private Vector3 _plantLocation;
private Vector3 _plantNormal;
public Vector3 PlayerDashLocation { get; set; }
public Vector3 PlantLocation { get; set; }
public Vector3 PlantNormal { get; set; }
public void Init(Node3D head, Camera3D camera)
{
@ -51,8 +51,8 @@ public partial class WeaponSystem : RigidBody3D
_weaponState.SendEvent("throw");
_throwDirection = (end - GlobalPosition).Normalized();
_plantLocation = collisionLocation;
_plantNormal = collisionNormal;
PlantLocation = collisionLocation;
PlantNormal = collisionNormal;
LookAt(end);
var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(end, StraightThrowDuration));
@ -72,9 +72,13 @@ public partial class WeaponSystem : RigidBody3D
{
_weaponState.SendEvent("plant");
Freeze = true;
GlobalPosition = _plantLocation;
PlayerDashLocation = ComputeDashLocation(_plantLocation, _plantNormal);
LookAt(GlobalTransform.Origin + _plantNormal, Vector3.Up, true);
GlobalPosition = PlantLocation;
LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
}
public void OnThrownWeaponReachesGround(Node other)
{
PlantWeaponInWall();
}
public void ResetWeapon()
@ -83,26 +87,25 @@ public partial class WeaponSystem : RigidBody3D
Transform = _startTransform;
Freeze = true;
}
private Vector3 ComputeDashLocation(Vector3 collisionLocation, Vector3 collisionNormal)
{
return collisionLocation + collisionNormal * 0.2f;
}
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
base._IntegrateForces(state);
PlayerDashLocation = GlobalPosition;
if (!Freeze && state.GetContactCount() > 0)
{
_plantLocation = state.GetContactLocalPosition(0);
_plantNormal = state.GetContactLocalNormal(0);
PlayerDashLocation = ComputeDashLocation(_plantLocation, _plantNormal);
PlantLocation = state.GetContactLocalPosition(0);
PlantNormal = state.GetContactLocalNormal(0);
}
}
public void OnThrownWeaponReachesGround(Node other)
public bool IsPlantedUnderPlatform()
{
PlantWeaponInWall();
return PlantedState.Active && GlobalRotation.X > 1 && Math.Abs(GlobalRotation.Y) > 1;
}
public bool IsPlantedInWall()
{
return PlantedState.Active && Math.Abs(GlobalRotation.X) + Math.Abs(GlobalRotation.Z) < 0.3;
}
}