+1 vote

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;
        }

    }
}
Godot version 3.2.3
in Engine by (17 points)

1 Answer

–2 votes

acculy im new and i dont know much about godot
this will about you kb physics

by (56 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.