#Space State picks up imaginary collision along vertical line
1 messages · Page 1 of 1 (latest)
Yup. As I said, the collissions usually work, stopping the line when it hits a platform, but like 20% of the time with platforms, it won't register, and of course, the line collides with the foreground tilemap in x = 96 no matter what.
I'm leaning more and more towards this being a bug with the engine itself
And thanks for responding, btw. This issue has been driving me mad
But if it's a relative position and the ray query requires absolute positions...
Very unlikely that it is a bug
Oh...
Busy rn but I'll get back to you in an hour or two, hopefully with good news. Thanks😄
You were completely right. When adding the Line2D's global position to points between which I wanted to check for a collission, it works with no issues at all. Thank you so much! 😄
My final code:
extends Line2D
@export_custom(PROPERTY_HINT_LAYERS_2D_PHYSICS, "") var collision_mask = PROPERTY_HINT_LAYERS_2D_PHYSICS
var grav = ProjectSettings.get_setting("physics/2d/default_gravity")
var dotGap = 0.1 # How many seconds of travel go between each dot
var space_state
var globalpos
func make_points() -> void:
var yvel = get_parent().chargedJumpPower
var xvel = get_parent().chargedDirectionPower
clear_points()
for i in range(0, 40):
add_point(Vector2(i * dotGap * xvel, 0.5*grav*(i*dotGap)*(i*dotGap) - yvel * (i * dotGap)))
if (i < 2):
pass
else:
var query = PhysicsRayQueryParameters2D.create(get_point_position(i - 1) + globalpos, get_point_position(i) + globalpos, collision_mask)
if space_state.intersect_ray(query):
remove_point(i)
add_point(space_state.intersect_ray(query).position - globalpos)
break
queue_redraw()
func _draw() -> void:
for i in range(get_point_count()):
draw_circle(get_point_position(i), 2, Color.WHITE)
if stopline and i == get_point_count() -1:
draw_circle(get_point_position(i), 4, Color.GREEN)
func _physics_process(delta: float) -> void:
globalpos = get_global_position()
space_state = get_world_2d().direct_space_state
if get_parent().charging:
make_points()
else:
clear_points()
queue_redraw()