gd: added wall hugging
This commit is contained in:
45
systems/wall_hug/WallHugSystem.cs
Normal file
45
systems/wall_hug/WallHugSystem.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RustyOptions;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
public partial class WallHugSystem : Node3D
|
||||
{
|
||||
|
||||
private List<RayCast3D> _raycasts;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_raycasts = new List<RayCast3D>();
|
||||
_raycasts.Add(GetNode<RayCast3D>("front"));
|
||||
_raycasts.Add(GetNode<RayCast3D>("back"));
|
||||
_raycasts.Add(GetNode<RayCast3D>("left"));
|
||||
_raycasts.Add(GetNode<RayCast3D>("right"));
|
||||
}
|
||||
|
||||
public bool IsWallHugging()
|
||||
{
|
||||
foreach (RayCast3D raycast in _raycasts)
|
||||
{
|
||||
if (raycast.IsColliding())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Option<Vector3> GetWallNormal()
|
||||
{
|
||||
foreach (RayCast3D raycast in _raycasts)
|
||||
{
|
||||
if (raycast.IsColliding())
|
||||
{
|
||||
return raycast.GetCollisionNormal().Some();
|
||||
}
|
||||
}
|
||||
return Option<Vector3>.None;
|
||||
}
|
||||
}
|
1
systems/wall_hug/WallHugSystem.cs.uid
Normal file
1
systems/wall_hug/WallHugSystem.cs.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://tjiji63wlom5
|
Reference in New Issue
Block a user