Spent too much time fixing slope movement

This commit is contained in:
Dustin 2025-06-03 14:37:44 -07:00
parent a387d74138
commit 76e7f5ef19
4 changed files with 38 additions and 14 deletions

View File

@ -2,7 +2,7 @@
[ext_resource path="res://src/classes/camera_guide.gd" type="Script" id=1]
[ext_resource path="res://src/Camera2D.gd" type="Script" id=2]
[ext_resource path="res://src/levels/CloneBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/levels/TestBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/ui/HUD.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Main.gd" type="Script" id=7]

View File

@ -18,16 +18,16 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=6]
points = PoolVector2Array( 0, 15.8622, 0, 12.2812, 0, 8.62056, 16, 0, 16, 16 )
points = PoolVector2Array( 0, 16, 0, 8, 0, 8, 16, 0, 16, 16 )
[sub_resource type="ConvexPolygonShape2D" id=7]
points = PoolVector2Array( 16, 8.69844, 16, 16, 0, 16 )
points = PoolVector2Array( 16, 8, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=8]
points = PoolVector2Array( 0, 0, 16, 8.46479, 16, 16, 0, 16 )
points = PoolVector2Array( 0, 0, 16, 8, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=9]
points = PoolVector2Array( 0, 8.62056, 16, 16, 0, 16 )
points = PoolVector2Array( 0, 8, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=10]
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )

View File

@ -40,6 +40,8 @@ const UP = -1.0
const DOWN = 1.0
const LEFT = -1.0
const RIGHT = 1.0
#const TILE_SIZE = 4
var FLOOR_ANGLE_THRESHOLD := deg2rad(60)
func _ready():
#velocity_controller.debug = true
@ -164,10 +166,24 @@ func apply_state_modifier(movement_parameters :MovementParameters) -> MovementPa
## Passed in acceleration, vel, etc is applied to whatever
## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted
func apply_movement_to_parent( _velocity :Vector2) -> void:
var snap = Vector2.DOWN * 8
## Disable snap when trying to jump (hacky?)
if _velocity.y < -8:
snap = Vector2.ZERO
if parent is KinematicBody2D:
velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true)
#var snap = Vector2((_velocity.normalized().x * -1 * TILE_SIZE) ,DOWN * TILE_SIZE)
var snap = Vector2.DOWN #* TILE_SIZE
#var snap = Vector2.DOWN
## Disable snap when trying to jump (hacky?)
if !current_state.is_grounded:
snap = Vector2.ZERO
if parent is KinematicBody2D:
#velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true, 4, FLOOR_ANGLE_THRESHOLD)
#velocity_controller.velocity.x = parent.move_and_slide(_velocity,Vector2.UP,false,TILE_SIZE,FLOOR_ANGLE_THRESHOLD).x
velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true, 4, FLOOR_ANGLE_THRESHOLD)
if !parent.is_on_floor() and parent.get_slide_count() == 0:
var collision_to_floor = parent.get_floor_angle()
var collision_count = parent.get_slide_count()
var foo = 2+2
#move_and_slide_with_snap(linear_velocity: Vector2, snap: Vector2, up_direction: Vector2 = Vector2( 0, 0 ), stop_on_slope: bool = false, max_slides: int = 4, floor_max_angle: float = 0.785398, infinite_inertia: bool = true)

View File

@ -397,9 +397,6 @@ func _state_process_physics_move():
request_state_change.call_func('idle')
return
if !parent.is_on_floor():
request_state_change.call_func('fall')
return
## First version
#move_actor_as_desired()
@ -416,6 +413,17 @@ func _state_process_physics_move():
desired_movement_vector )
)
## Doing this after the call of movement
if !parent.is_on_floor():
request_state_change.call_func('fall')
return
# var slide_count = parent.get_slide_count()
# ## TODO: Our impulse model can't handle zero
# if velocity_controller.velocity.y > - 2 and parent.get_slide_count() == 0:
# request_state_change.call_func('fall')
# return
func get_climb_shape_location() -> Vector2:
if $"%LadderDetector".is_colliding():
var point: Vector2 = $"%LadderDetector".get_collision_point()