Improving rope disconnecting technique
Now compares the angle of the old connection to the new one and based off of the attachment being from clockwise movement or counterclockwise movement, it disconnects Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
parent
1f4c6514e0
commit
ed9643f386
@ -60,33 +60,12 @@ func clear_rope() -> void:
|
||||
pop_rope_seg()
|
||||
|
||||
|
||||
func angle_valid_release_rope(a1:float, a2:float, cw:bool) -> bool:
|
||||
func angle_valid_release_rope(a1:float, cw:bool) -> bool:
|
||||
var result : bool
|
||||
a1 = fmod(a1+PI, 2*PI) # 0 to 2PI
|
||||
a2 = fmod(a2+PI, 2*PI)
|
||||
#print(abs(a1-a2))
|
||||
var diff : float = PI - abs(abs(a1 - a2) - PI)
|
||||
#print("angle diff: ", PI - abs(abs(a1 - a2) - PI))
|
||||
#var angle_margin : float = 0.09
|
||||
var within_angle : bool = diff < 0.2
|
||||
|
||||
# https://math.stackexchange.com/questions/110080/shortest-way-to-achieve-target-angle#:~:text=If%20a%3Eb%2C%20and%20a,b%3E180%2C%20turn%20counterclockwise.
|
||||
|
||||
var temp = [a2 - a1, a2 - a1 + 2*PI, a2 - a1 - 2*PI]
|
||||
#var alpha = a2 - a1 # T - C
|
||||
#var beta = a2 - a1 + 2*PI
|
||||
#var gamma = a2 - a1 - 2*PI
|
||||
var smallest = temp[0]
|
||||
for i in temp:
|
||||
if abs(i) < abs(smallest):
|
||||
smallest = i
|
||||
|
||||
result = smallest > 0 # if it's positive
|
||||
|
||||
if not cw:
|
||||
result = not result
|
||||
|
||||
result = result and within_angle
|
||||
if cw:
|
||||
result = a1 < 0
|
||||
else:
|
||||
result = a1 > 0
|
||||
|
||||
return result
|
||||
|
||||
@ -103,7 +82,7 @@ func check_new_coll():
|
||||
if player.rope_length - dist > DIST_MARGIN:
|
||||
|
||||
shift_add_rope_seg(col_point)
|
||||
rope_segments[-2].connection_angle = rope_segments[-2].conn_point.angle_to_point(player.global_position)
|
||||
#rope_segments[-2].connection_angle = rope_segments[-2].conn_point.angle_to_point(player.global_position)
|
||||
var tangent : Vector2 = col_point - player.global_position
|
||||
tangent = Vector2(tangent.y, -tangent.x)
|
||||
rope_segments[-2].clockwise = player.velocity.dot(tangent) > 0
|
||||
@ -119,7 +98,7 @@ func check_new_coll():
|
||||
#print("looping")
|
||||
if rope_segments[counter].rope_ray.is_colliding(): # safety check
|
||||
if rope_segments[counter].conn_point.distance_to(rope_segments[counter].rope_ray.get_collision_point()) < DIST_MARGIN and \
|
||||
angle_valid_release_rope(rope_segments[counter].conn_point.angle_to_point(player.global_position), rope_segments[counter].connection_angle, rope_segments[counter].clockwise): # if the collision of the other ray is longer (so it can see the earlier connection point)
|
||||
angle_valid_release_rope((rope_segments[counter].conn_point - player.global_position).angle_to(rope_segments[counter+1].conn_point - player.global_position), rope_segments[counter].clockwise): # if the collision of the other ray is longer (so it can see the earlier connection point)
|
||||
player.connection_point = rope_segments[counter].conn_point
|
||||
player.rope_length = player.global_position.distance_to(player.connection_point)
|
||||
shift_pop_rope_seg()
|
||||
@ -145,29 +124,5 @@ func _process(delta: float) -> void:
|
||||
check_new_coll()
|
||||
|
||||
|
||||
#if is_colliding(): # safety if statement. should always be true realistically
|
||||
##print("passive")
|
||||
#var col_point : Vector2 = get_collision_point()
|
||||
#var dist : float = player.position.distance_to(col_point)
|
||||
##print(col_point," ", player.connection_points[-1])
|
||||
##if dist < fire_range:
|
||||
##print(dist, " ", player.position.distance_to(player.connection_points[-1]))
|
||||
##
|
||||
#while dist - player.position.distance_to(player.connection_points[-1]) > 10: #margin of 10
|
||||
#print("yowdy")
|
||||
#if (player.connection_points.size() > 1):
|
||||
#print(player.connection_points)
|
||||
#print("hi")
|
||||
#player.connection_points.remove_at(player.connection_points.size()-1)
|
||||
#player.rope_length = dist
|
||||
#print("bye")
|
||||
#else:
|
||||
#break
|
||||
##while player.connection_points[-1].distance_to(col_point) > 5: # margin
|
||||
##
|
||||
#if player.rope_length - dist > 10:
|
||||
#print("add")
|
||||
#player.connection_points.append(col_point)
|
||||
#player.rope_length = dist
|
||||
pass
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user