Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | brunosxs | |
Old Version | Published before Godot 3 was released. |
Is there a method or a better way to get specific points in a collisionBox2D?
I am programming a physics engine where the character is instantiated at runtime, and I was trying to get him to fire rays to handle the collision with slopes.
My solution works but it is far from elegant and optimized
I created a function that returns a dictionary filled with the corners of the collisionBox2D relative to the parent node(the global position)
func get_corners():
raycast_origins = {
top_left = self.get_global_pos() + self.get_node("hitbox").get_shape().get_extents()*Vector2(-1,-1)+Vector2(skin,skin),
top_right = self.get_global_pos() + self.get_node("hitbox").get_shape().get_extents()*Vector2(1,-1)+Vector2(-skin,skin),
bottom_left = self.get_global_pos() + self.get_node("hitbox").get_shape().get_extents()*Vector2(-1,1)+Vector2(skin,-skin),
bottom_right = self.get_global_pos() + self.get_node("hitbox").get_shape().get_extents()*Vector2(1,1)+Vector2(-skin,-skin)
}
return raycast_origins
#Then, a second function shots the rays:
func ray_check():
var ray_check = {
top_right = space_state.intersect_ray(get_corners().top_right,get_corners().top_right+Vector2(raycast_step*1,0) ,[self] ),
middle_right = space_state.intersect_ray(get_corners().top_right-Vector2(0,self.get_node("hitbox").get_shape().get_extents().y,get_corners().top_right-Vector2(0,get_corners().top_right-Vector2(0,self.get_node("hitbox").get_shape().get_extents().y)+Vector2(raycast_step*1,0) ,[self] )))
}
return ray_check
So, I’d like to know how you guys would approach this or if I am on the right path, how can I optimize the formula.