0 votes

In my game the player can teleport but can_teleport_to(location) only checks for intersection and not if the player's collision shapes are inside of anything. I understand why although I argue the method name should be changed.

Anyway I tried to get around this by casting a ray from the teleport location to the current location of the player and if the surface normal of the first collision is facing away from the ray (using the dot product and a vector) the teleport target is inside something. This can be repeated with an additional ray going straight up if the first collision is the heightmapped terrain to account for hollow bottomed bodies. The only issue is if static bodies are intersecting but it's not an issue for my game.

I was happy with this thinking I was onto a simple, efficient solution but when I raycast through a collision surface the reported normal of that surface is reversed (even in the same collision position) if the ray is coming from the other side, making this method impossible to use.

As a rough example this is what gets printed:

(collider:[StaticBody:705]), (collider_id:705), (normal:(0, 0, 1)), (position:(-2.094037, 0.04, -11.912519)), (rid:[RID]), (shape:0)
(collider:[StaticBody:705]), (collider_id:705), (normal:(-0, -0, -1)), (position:(-2.142617, 0.04, -11.912519)), (rid:[RID]), (shape:0)

I don't know if this raycast thing is a bug but I'm stumped regardless.

asked Sep 4, 2017 in Engine by Atort (12 points)

1 Answer

0 votes

Have you tried multiplying the reported normal by -1 ? doing this might invert the direction of the normal, which is what you want right ?

answered Sep 7, 2017 by dennisb (19 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 How to use this Q&A? before posting your first questions.