+2 votes

in 3D space!
Monster detect player with Area/CollisionPolygon
I want to check if monster has free sight and not a wall between the monster and the player!
I try use "RayCast.cast_to"
an example I am trying:
$RayCast.cast _ to = transform.xform(player.transform.origin)

Someone know a easy way to see if something is in between player and the Monster?
underscore don't show right: cast underscore to "cast_to"

in Engine by (14 points)

1 Answer

+1 vote

Isn't right but neither would be


Because that would give you the players position as if it is a child of monster.

You need to take the monster's position away from the player's position.

player.transform.origin - transform.origin
by (3,225 points)

Thanks for give me confidence in: player.transform.origin - transform.origin

I end up with this $RayCast.castto:
to = Vector3(transform.origin.x - player.transform.origin.x, player.transform.origin.z - transform.origin.z, player.transform.origin.y - transform.origin.y + 0.1)

I sit and do one value: X, Y; Z at a time and Debug / Visible Collision Shapes On

my gravity is:
var gravity = Vector3.DOWN * 12
Have I somehow turn my world to Vector3(X, Z, Y)
My $RayCast.cast_to formula make me confused, but it works!

I stop the Mob to walking and turning!
When I start make Monster start turn again the $RayCast.castto start go wildly on my screen again!
It's something with the Monster direction that also somehow is in the calculation too!

Have I somehow turn my world to Vector3(X, Z, Y)

Have you imported a model as the top scene node and parented everything else under it?
In Godot you need to specify an initial node for the scene before anything else, I typically use Node for maps, Node2D or Spatial for anything with a specific custom behaviour and Control is for UI.

Finally was more easy than expected!
$RayCast.cast_to = $RayCast.to_local(player.transform.origin)

Thanks all for taking time try help me!

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.
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 webmaster@godotengine.org with your username.