Trying to slope rotate (futile style)
This commit is contained in:
parent
0c5c2112b4
commit
7c423e7fc9
@ -354,36 +354,85 @@ func execute_airstrafe(
|
||||
air_strafe_charges -= 1
|
||||
return linear_velocity
|
||||
|
||||
var snapped = false
|
||||
func execute_movement() -> void:
|
||||
if(GlobalState.is_dead):
|
||||
return
|
||||
var colliding_ray_number = 0
|
||||
var target_angle = 0
|
||||
var rotation_point: Vector2
|
||||
if(is_on_floor()):
|
||||
for raycast in $SlopeRaycasts.get_children():
|
||||
if(raycast.is_colliding()):
|
||||
colliding_ray_number += 1
|
||||
var collision_normal = raycast.get_collision_normal()
|
||||
target_angle += Vector2.UP.angle_to(collision_normal)
|
||||
target_angle = rotation + target_angle/max(colliding_ray_number,1)
|
||||
rotation_point = sign(target_angle) * Vector2($BlobbyBody.shape.extents.x + $BlobbyBody.to_local(position).x, 0)
|
||||
print(rotation_point)
|
||||
if(target_angle == 0 || colliding_ray_number < 2):
|
||||
rotation = 0
|
||||
velocity = move_and_slide(velocity, FLOOR_NORMAL,true, 4, 0.785398,false)
|
||||
var snap = Vector2.DOWN * 128
|
||||
var center_floor_rot = 0
|
||||
var floor_rot = 0
|
||||
# get rotation of floor, compare collided floor with floor under center
|
||||
if is_on_floor():
|
||||
# TODO: Problem when correctly rotating?
|
||||
center_floor_rot = $SlopeRaycast.get_collision_normal().angle() + PI/2
|
||||
floor_rot = get_floor_normal().angle() + PI/2
|
||||
if(abs(center_floor_rot) > PI/4+0.1):
|
||||
center_floor_rot = floor_rot
|
||||
# snap when on slopes
|
||||
if(abs(floor_rot) > 0.1 || abs(center_floor_rot) > 0.1):
|
||||
velocity = move_and_slide_with_snap(velocity.rotated(floor_rot),
|
||||
snap, FLOOR_NORMAL, true)
|
||||
snapped = true
|
||||
# normal slide on flat floor
|
||||
else:
|
||||
velocity = move_and_slide(velocity, FLOOR_NORMAL,true, 4, 0.785398,false)
|
||||
var translation = rotation_point.rotated(target_angle) - rotation_point
|
||||
# if(target_angle == 0):
|
||||
# position.x += translation.xddddad
|
||||
# position.y += translation.y
|
||||
rotation = target_angle
|
||||
|
||||
|
||||
if snapped == true:
|
||||
print("unsnapped")
|
||||
velocity = move_and_slide(velocity.rotated(floor_rot),FLOOR_NORMAL)
|
||||
snapped = false
|
||||
# rotate related to floor slope
|
||||
var rot = calculate_slope_rotation(center_floor_rot)
|
||||
# Convert velocity back to local space.
|
||||
velocity = velocity.rotated(-floor_rot)
|
||||
|
||||
func calculate_slope_rotation(center_floor_rot: float) -> float:
|
||||
var angle = 0
|
||||
# var distance_to_slope_left = abs($SlopeRaycastLeft.global_position.distance_to($SlopeRaycastLeft.get_collision_point()))
|
||||
# var distance_to_slope_right = abs($SlopeRaycastRight.global_position.distance_to($SlopeRaycastRight.get_collision_point()))
|
||||
# var slope_angle_left = rad2deg($SlopeRaycastLeft.get_collision_normal().rotated(PI/2).angle())
|
||||
# var slope_angle_right = rad2deg($SlopeRaycastRight.get_collision_normal().rotated(PI/2).angle())
|
||||
# if(abs(slope_angle_left - slope_angle_right) < 5):
|
||||
# print("on slope")
|
||||
# elif(abs(slope_angle_left) > 0 && distance_to_slope_left < distance_to_slope_right ||
|
||||
# abs(slope_angle_right) > 0 && distance_to_slope_right < distance_to_slope_left):
|
||||
# print("upturn")
|
||||
# var length_vector: Vector2 = $SlopeRaycastRight.get_collision_point() - $SlopeRaycastLeft.get_collision_point()
|
||||
# angle = length_vector.angle()
|
||||
# print(rad2deg(angle))
|
||||
# else:
|
||||
# print("downturn")
|
||||
# var length_vector: Vector2 = $SlopeRaycastRight.get_collision_point() - $SlopeRaycastLeft.get_collision_point()
|
||||
# angle = length_vector.angle()
|
||||
# # angle = center_floor_rot * min(1, 1.3*overhang(distance_to_slope_left, distance_to_slope_right)/$BlobbyBody.shape.extents.x)
|
||||
if(player_state_machine.facing == 1):
|
||||
var length_vector: Vector2 = $SlopeRaycastRight.get_collision_point() - $SlopeRaycastLeft.get_collision_point()
|
||||
|
||||
angle = length_vector.angle()
|
||||
print(rad2deg(angle))
|
||||
return angle
|
||||
|
||||
# When Blobby is going over an edge,
|
||||
# This function returns how many pixels he has gone over that edge, measured from his center
|
||||
func overhang(distance_to_slope_left, distance_to_slope_right) -> float:
|
||||
var distance_to_slope = abs($SlopeRaycast.global_position.distance_to($SlopeRaycast.get_collision_point()))
|
||||
if(!(abs(distance_to_slope_left) > 1 || abs(distance_to_slope_right) > 1)):
|
||||
distance_to_slope = max(1,distance_to_slope)
|
||||
var hitbox_to_slope_vector = (global_position - $SlopeRaycast.get_collision_point()).normalized()
|
||||
var angle = min(PI/2,abs(hitbox_to_slope_vector.angle_to($SlopeRaycast.get_collision_normal().rotated(PI/2))))
|
||||
var overhang = distance_to_slope * tan(angle)
|
||||
overhang = $BlobbyBody.shape.extents.x if abs(overhang) > $BlobbyBody.shape.extents.x else overhang
|
||||
# if(overhang < 0.6):
|
||||
# print("dist to slope:")
|
||||
# print(distance_to_slope)
|
||||
# print("hitbox to slope vec:")
|
||||
# print(hitbox_to_slope_vector)
|
||||
# print("angle:")
|
||||
# print(rad2deg(angle))
|
||||
# print("tan(angle):")
|
||||
# print(tan(angle))
|
||||
# print("overhang:")
|
||||
# print(overhang)
|
||||
return abs(overhang)
|
||||
|
||||
#TODO Limit movement
|
||||
func die() -> void:
|
||||
z_index = 1
|
||||
GlobalState.is_dead = true
|
||||
|
||||
@ -1778,7 +1778,7 @@ tracks/4/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( -0.0287741, -8.97473 ) ]
|
||||
"values": [ Vector2( -1, -9 ) ]
|
||||
}
|
||||
tracks/5/type = "value"
|
||||
tracks/5/path = NodePath("../WallRaycasts/RightWallRaycast/Right_Wallcast1:position")
|
||||
@ -4474,7 +4474,7 @@ root_motion_track = NodePath(".")
|
||||
parameters/playback = SubResource( 48 )
|
||||
parameters/ducking/blend_position = 1.0
|
||||
parameters/falling/blend_position = 1.0
|
||||
parameters/idling/blend_position = 1.0
|
||||
parameters/idling/blend_position = 1.35307
|
||||
parameters/jumpToFall/blend_position = 1.0
|
||||
parameters/jumping/blend_position = 1.0
|
||||
parameters/runToJump/blend_position = 1.0
|
||||
@ -4598,19 +4598,21 @@ exclude_parent = false
|
||||
cast_to = Vector2( 1.5, 0 )
|
||||
collision_mask = 56
|
||||
|
||||
[node name="SlopeRaycasts" type="Node2D" parent="."]
|
||||
position = Vector2( 0, -1 )
|
||||
|
||||
[node name="SlopeRaycast" type="RayCast2D" parent="SlopeRaycasts"]
|
||||
position = Vector2( 14, 0 )
|
||||
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
|
||||
position = Vector2( -9, 0 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, 19 )
|
||||
cast_to = Vector2( 0, 32 )
|
||||
collision_mask = 56
|
||||
|
||||
[node name="SlopeRaycast2" type="RayCast2D" parent="SlopeRaycasts"]
|
||||
position = Vector2( -12, 0 )
|
||||
[node name="SlopeRaycast" type="RayCast2D" parent="."]
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, 19 )
|
||||
cast_to = Vector2( 0, 16 )
|
||||
collision_mask = 56
|
||||
|
||||
[node name="SlopeRaycastRight" type="RayCast2D" parent="."]
|
||||
position = Vector2( 10, 0 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 0, 32 )
|
||||
collision_mask = 56
|
||||
|
||||
[connection signal="area_entered" from="BlobbySkin" to="." method="_on_BlobbySkin_area_entered"]
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user