![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | calinleafshade |
I’m trying to make a Dishonoured-like blink system which shows a marker to show where you will blink to.
This all works fine except that its possible to blink through the ceiling because the Raycast hits the ceiling and so the origin of the player (the feet) is set to the ceiling which clips them through.
The solution to this is to resolve the collision with a capsule in the marker so that I can guarantee that the player can blink to that location.
How do I do this? The KinematicBody Node can be moved with a relative vector but I can’t find a way to place it at the raycast point and then resolve the collision and display the marker in the right place.
My current code is:
using Godot;
public class Blink : RayCast
{
private KinematicBody sprite;
public override void _Ready()
{
sprite = GetNode<KinematicBody>("Marker");
sprite.SetAsToplevel(true);
sprite.Hide();
}
public override void _Input(InputEvent @event) {
if (@event.IsActionPressed("blink")) {
sprite.Show();
}
else if (@event.IsActionReleased("blink")) {
sprite.Hide();
}
}
public Vector3 GetBlinkPosition() {
if (this.IsColliding()) {
return this.GetCollisionPoint();
} else {
return this.GlobalTransform.origin + -this.GlobalTransform.basis.z * this.CastTo.Length();
}
}
public override void _Process(float delta)
{
if (sprite.Visible) {
var t = sprite.GlobalTransform;
t.origin = this.GetBlinkPosition();
sprite.GlobalTransform = t;
}
}
}