godot-jolt: Shape-casting with cylinders and rectangular shapes report incorrect normals
Take this code:
func trace_standard(origin : Vector3, dest : Vector3, shape : Shape3D, e, mask):
var params : PhysicsShapeQueryParameters3D
var space_state
var results
# Create collision parameters
params = PhysicsShapeQueryParameters3D.new()
params.set_shape(shape)
params.transform.origin = origin
params.set_collide_with_bodies(true)
params.set_exclude([e])
params.set_motion(dest - origin)
params.set_margin(0.04)
params.set_collision_mask(mask)
hit = false
# Get distance fraction and position of first collision
space_state = get_world_3d().direct_space_state
results = space_state.cast_motion(params)
if !results.is_empty():
fraction = results[0]
endpos = origin + (dest - origin).normalized() * (origin.distance_to(dest) * fraction)
else:
fraction = 1
endpos = dest
return # didn't hit anything
hit = true
# Set next parameter position to endpos
params.transform.origin = endpos
# Get collision normal
results = space_state.get_rest_info(params)
if !results.is_empty():
normal = results.get("normal")
else:
normal = Vector3.UP
print(results)
I use this to do quake-style stair stepping. results is always { }, leading me to believe that for Cylinder Collision Shapes, the PhysicsShapeQueryParameters3D doesn’t work properly.
I am using the latest version of Jolt and Godot 4.0.2 stable.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 23 (12 by maintainers)
Yeah, I don’t know the answer to that, unfortunately. I suspect it becomes more relevant for complex convex polygons, or very large quantities of the applicable shapes.
Anyway, I’ll go ahead and close this again then, since there’s not really any showstoppers here other than unfortunate UX, and perhaps lacking documentation on my part. I’ll see if I can maybe make this clearer in the README somehow. It’s a lot to unpack though, as you can tell.
I’ll create a separate issue for the slight jitter caused by
safe_margin. I suspect I’ll need to forward that one upstream to Jolt.I’ve also added the project setting for disabling shape margins to my TODO list, so expect to see that in the changelog of an upcoming release.