gd: fixed look inputs
This commit is contained in:
58
systems/mantle/MantleSystem.cs
Normal file
58
systems/mantle/MantleSystem.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
|
||||
public partial class MantleSystem: Node3D
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,2,0.1,suffix:m,or_greater")]
|
||||
public float MantleEndLocationDistanceFromWall { get; set; } = 1f;
|
||||
[Export(PropertyHint.Range, "0,10,0.1,suffix:m,or_greater")]
|
||||
public float MantleHeightCastStart { get; set; } = 2f;
|
||||
[Export(PropertyHint.Range, "0,10,0.01,suffix:m,or_greater")]
|
||||
public float MaxStepHeight = 0.5f;
|
||||
|
||||
private Node3D _head;
|
||||
private ShapeCast3D _wallInFrontCast3D;
|
||||
private ShapeCast3D _mantleCast3D;
|
||||
private RayCast3D _mantleCheckCast3D;
|
||||
|
||||
public void Init(Node3D head)
|
||||
{
|
||||
_head = head;
|
||||
_wallInFrontCast3D = GetNode<ShapeCast3D>("WallInFrontCast3D");
|
||||
_mantleCast3D = GetNode<ShapeCast3D>("MantleCast3D");
|
||||
}
|
||||
|
||||
public Option<Vector3> FindMantleInFrontOfPlayer()
|
||||
{
|
||||
_wallInFrontCast3D.SetRotation(new Vector3(
|
||||
_wallInFrontCast3D.Rotation.X,
|
||||
_head.Rotation.Y,
|
||||
_wallInFrontCast3D.Rotation.Z));
|
||||
|
||||
if (!_wallInFrontCast3D.IsColliding())
|
||||
{
|
||||
return Option<Vector3>.None;
|
||||
}
|
||||
|
||||
var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
|
||||
var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0);
|
||||
return FindMantleLocationAtPoint(collisionPoint, collisionNormal);
|
||||
}
|
||||
|
||||
public Option<Vector3> FindMantleLocationAtPoint(Vector3 point, Vector3 wallNormal)
|
||||
{
|
||||
var horizontalEndLocation = point - wallNormal * MantleEndLocationDistanceFromWall;
|
||||
var shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
|
||||
|
||||
_mantleCast3D.SetGlobalPosition(shapeCastStartLocation);
|
||||
var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
|
||||
_mantleCast3D.SetTargetPosition(targetLocation);
|
||||
|
||||
if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y > 0.9f)
|
||||
return Option.Some(_mantleCast3D.GetCollisionPoint(0));
|
||||
return Option<Vector3>.None;
|
||||
}
|
||||
}
|
1
systems/mantle/MantleSystem.cs.uid
Normal file
1
systems/mantle/MantleSystem.cs.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bja6tis1vaysu
|
28
systems/mantle/mantle_system.tscn
Normal file
28
systems/mantle/mantle_system.tscn
Normal file
@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://wq1okogkhc5l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bja6tis1vaysu" path="res://systems/mantle/MantleSystem.cs" id="1_2oobp"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4coqe"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_qu4wy"]
|
||||
height = 1.5
|
||||
|
||||
[node name="MantleSystem" type="Node3D"]
|
||||
script = ExtResource("1_2oobp")
|
||||
MantleEndLocationDistanceFromWall = 0.2
|
||||
MantleHeightCastStart = 3.0
|
||||
|
||||
[node name="MantleCast3D" type="ShapeCast3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_4coqe")
|
||||
target_position = Vector3(0, 0, 0)
|
||||
max_results = 1
|
||||
collision_mask = 2
|
||||
debug_shape_custom_color = Color(1, 0, 0, 1)
|
||||
|
||||
[node name="WallInFrontCast3D" type="ShapeCast3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("CapsuleShape3D_qu4wy")
|
||||
target_position = Vector3(0, 0, -1.5)
|
||||
max_results = 1
|
||||
collision_mask = 2
|
||||
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
|
Reference in New Issue
Block a user