0 votes

I am creating procedural shapes, so they are empty scene with a script that creates all the hierarchy when the scene is instanced because all is triggered in ready()

the issue is, I would like to raycast from random points to the mesh to place other nodes on the surface of my geometry.

but I can't find a way to use raycasting in the _ready() function, if I instance a raycast or use GetWorld().IntersectRay(), it won't return anything if triggered from ready()

It does work from _PhysicProcess(), but I would like to not have to spread the generation on different frames

EDIT: I found that it works perfectly with standard physic bodies, my issue come from the fact that I am using CSG shapes (that does respond to other physic interactions) which are a bit more touchy for the physic server;

It works when I replace the CSG combiner with a static body

in Engine by (59 points)
edited by

You could probably use a RayCast Node instead and use force_raycast_update() to get it work in _ready().

1 Answer

+1 vote

You can use (for 3d):

var phy = PhysicsServer.space_get_direct_state(get_world().space)
var ray = phy.intersect_ray(from, to, exclude = [], collision_mask = 1)

might as well check the docs for this function, but for me it worked in _ready()

EDIT: Didn't see it was marked as C# but i will keep it here in case anyone else will make use of it

by (1,181 points)

thanks I already tried that, my code was

PhysicsDirectSpaceState space = PhysicsServer.SpaceGetDirectState(GetWorld().Space);
Godot.Collections.Dictionary collision = space.IntersectRay(new Vector3(0, 50, 0), new Vector3(0, -50, 0));

it does work in the _ready() function for collisions with static body nodes but not CSG shapes

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.