mantle system fix amazing
This commit is contained in:
@@ -14,17 +14,15 @@ public partial class MantleSystem: Node3D
|
||||
|
||||
private ShapeCast3D _wallInFrontCast3D;
|
||||
private ShapeCast3D _mantleCast3D;
|
||||
|
||||
|
||||
private ShapeCast3D _inAirWallDetect;
|
||||
private ShapeCast3D _groundedWallDetect;
|
||||
public Curve3D MantleCurve { get; private set; }
|
||||
|
||||
public bool IsMantlePossible { get; private set; } = false;
|
||||
public int NumberOfValidPofiles { get; private set; } = -1;
|
||||
public const int WallProfileCastCount = 7;
|
||||
|
||||
private ShapeCast3D[] _wallProfileShapecasts = new ShapeCast3D[WallProfileCastCount];
|
||||
public Vector3[] WallProfilePositions { get; private set; } = new Vector3[WallProfileCastCount];
|
||||
public Vector3[] WallProfileNormals { get; private set; } = new Vector3[WallProfileCastCount];
|
||||
|
||||
public void Init()
|
||||
{
|
||||
@@ -55,21 +53,15 @@ public partial class MantleSystem: Node3D
|
||||
SetCastsEnabled(isColliding);
|
||||
|
||||
// Reset state
|
||||
NumberOfValidPofiles = -1;
|
||||
IsMantlePossible = false;
|
||||
if (!isColliding)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!isColliding) return;
|
||||
|
||||
// Check if collide with wall
|
||||
var collisionNormal = isGrounded ? _groundedWallDetect.GetCollisionNormal(0) : _inAirWallDetect.GetCollisionNormal(0);
|
||||
if (collisionNormal.Y > 0.8f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NumberOfValidPofiles = 0;
|
||||
if (collisionNormal.Y > 0.9f) return;
|
||||
|
||||
MantleCurve = new Curve3D();
|
||||
MantleCurve.AddPoint(Vector3.Zero);
|
||||
var hasFirstProfileHit = false;
|
||||
foreach (var wallProfileShapecast in _wallProfileShapecasts)
|
||||
{
|
||||
@@ -81,9 +73,7 @@ public partial class MantleSystem: Node3D
|
||||
// Got to the other side of the wall, we stop there
|
||||
if (!wallProfileShapecast.IsColliding())
|
||||
{
|
||||
WallProfilePositions[NumberOfValidPofiles] = globalTargetPosition;
|
||||
WallProfileNormals[NumberOfValidPofiles] = Vector3.Zero;
|
||||
NumberOfValidPofiles += 1;
|
||||
MantleCurve.AddPoint(ToLocal(globalTargetPosition));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -92,16 +82,16 @@ public partial class MantleSystem: Node3D
|
||||
|
||||
// Check if we collided parallel to a wall
|
||||
var isCollisionSameAsTarget = globalTargetPosition.IsEqualApprox(profilePoint);
|
||||
var isCollidingWithWall = profileNormal.Y < 0.9f;
|
||||
var isCollidingWithWall = profileNormal.Y < 0.1f;
|
||||
if (isCollisionSameAsTarget || isCollidingWithWall) continue;
|
||||
|
||||
// We have a valid collision
|
||||
WallProfilePositions[NumberOfValidPofiles] = profilePoint;
|
||||
WallProfileNormals[NumberOfValidPofiles] = profileNormal;
|
||||
hasFirstProfileHit = true;
|
||||
NumberOfValidPofiles += 1;
|
||||
MantleCurve.AddPoint(ToLocal(profilePoint));
|
||||
}
|
||||
IsMantlePossible = NumberOfValidPofiles > 0; // Should always be true
|
||||
if (MantleCurve.PointCount == 1) return;
|
||||
|
||||
IsMantlePossible = true;
|
||||
}
|
||||
|
||||
public Option<Vector3> FindMantle()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://wq1okogkhc5l"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://wq1okogkhc5l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bja6tis1vaysu" path="res://systems/mantle/MantleSystem.cs" id="1_2oobp"]
|
||||
[ext_resource type="Shape3D" uid="uid://dp2p8v7demb5j" path="res://systems/mantle/find_wall_shape.tres" id="2_i32qj"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4coqe"]
|
||||
height = 1.7
|
||||
@@ -9,6 +8,13 @@ height = 1.7
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_2oobp"]
|
||||
radius = 0.75
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2oobp"]
|
||||
radius = 0.25
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_i32qj"]
|
||||
radius = 0.25
|
||||
height = 1.5
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_i32qj"]
|
||||
radius = 0.125
|
||||
|
||||
@@ -35,14 +41,14 @@ collision_mask = 2
|
||||
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
|
||||
|
||||
[node name="InAirWallDetect" type="ShapeCast3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.26, 0)
|
||||
shape = ExtResource("2_i32qj")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.01, 0)
|
||||
shape = SubResource("CapsuleShape3D_2oobp")
|
||||
target_position = Vector3(0, 0, -2)
|
||||
collision_mask = 2
|
||||
|
||||
[node name="GroundedWallDetect" type="ShapeCast3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.76, 0)
|
||||
shape = ExtResource("2_i32qj")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.26, 0)
|
||||
shape = SubResource("CapsuleShape3D_i32qj")
|
||||
target_position = Vector3(0, 0, -2)
|
||||
collision_mask = 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user