make trajectory use player movement calculation methods
This commit is contained in:
@@ -49,5 +49,7 @@ visible = false
|
||||
top_level = true
|
||||
script = ExtResource("6_tuyoq")
|
||||
_steps = 180
|
||||
_do_collisions = null
|
||||
_wall_bounce_velocity_loss = null
|
||||
_line_color = Color(1, 1, 0, 1)
|
||||
metadata/_custom_type_script = "uid://ceyu5der8j8gq"
|
||||
|
||||
@@ -622,7 +622,6 @@ metadata/_custom_type_script = "uid://ceyu5der8j8gq"
|
||||
position = Vector2(240, 328)
|
||||
script = ExtResource("4_74lek")
|
||||
_steps = 71
|
||||
_collide = false
|
||||
metadata/_custom_type_script = "uid://ceyu5der8j8gq"
|
||||
|
||||
[node name="Trajectory2" type="Marker2D" parent="Trajectories"]
|
||||
|
||||
@@ -102,9 +102,9 @@ const JUMP_REFERENCE: PackedFloat32Array = [
|
||||
set(value):
|
||||
_stop_on_landing = value
|
||||
queue_redraw()
|
||||
@export var _collide: bool = true:
|
||||
@export var _do_collisions: bool = true:
|
||||
set(value):
|
||||
_collide = value
|
||||
_do_collisions = value
|
||||
queue_redraw()
|
||||
@export var _draw_hitbox: bool = false:
|
||||
set(value):
|
||||
@@ -141,6 +141,10 @@ const JUMP_REFERENCE: PackedFloat32Array = [
|
||||
set(value):
|
||||
_fall_acceleration = value
|
||||
queue_redraw()
|
||||
@export var _wall_bounce_velocity_loss: float = 0.5:
|
||||
set(value):
|
||||
_wall_bounce_velocity_loss = value
|
||||
queue_redraw()
|
||||
|
||||
@export_group("Colors")
|
||||
@export var _line_color: Color = Color.MAGENTA
|
||||
@@ -190,30 +194,40 @@ func _draw() -> void:
|
||||
var pos_min := pos
|
||||
var pos_max := pos
|
||||
|
||||
var is_on_floor: bool = false
|
||||
var flipping: float = -1.0 if flip else 1.0
|
||||
var velocity: Vector2
|
||||
velocity.y = (-_jump_force * charge_strength) if _jump else 0.0
|
||||
velocity.x = _jump_speed * flipping
|
||||
var is_on_floor: bool = false
|
||||
var direction: float = -1.0 if flip else 1.0
|
||||
|
||||
for i in range(_steps):
|
||||
pos += velocity * delta
|
||||
if is_on_floor and _stop_on_landing:
|
||||
break
|
||||
|
||||
velocity.y = (
|
||||
move_toward(velocity.y, _fall_speed, delta * _fall_acceleration)
|
||||
if not is_on_floor
|
||||
else 0.0
|
||||
velocity = (
|
||||
Player
|
||||
. process_movement(
|
||||
velocity,
|
||||
delta,
|
||||
is_on_floor,
|
||||
direction,
|
||||
false,
|
||||
charge_strength,
|
||||
i == 0,
|
||||
_move_speed,
|
||||
_jump_speed,
|
||||
_jump_force,
|
||||
_fall_speed,
|
||||
_fall_acceleration,
|
||||
)
|
||||
)
|
||||
|
||||
if _collide:
|
||||
if _do_collisions:
|
||||
var motion_proportion := _cast_motion(pos_prev, pos)
|
||||
if not is_equal_approx(motion_proportion, 1.0):
|
||||
var is_hitting_floor: bool = false
|
||||
var is_hitting_ceiling: bool = false
|
||||
var motion := (pos - pos_prev) * motion_proportion
|
||||
pos = pos_prev + motion
|
||||
var is_hitting_floor: bool = false
|
||||
var is_hitting_ceiling: bool = false
|
||||
|
||||
# hitting floor
|
||||
if velocity.y > 0 and not is_on_floor:
|
||||
@@ -229,22 +243,32 @@ func _draw() -> void:
|
||||
if raycast_result:
|
||||
is_hitting_ceiling = true
|
||||
|
||||
var is_hitting_wall: bool = (
|
||||
not is_hitting_floor and not is_hitting_ceiling
|
||||
)
|
||||
|
||||
velocity = (
|
||||
Player
|
||||
. process_collision(
|
||||
velocity,
|
||||
velocity,
|
||||
is_hitting_ceiling,
|
||||
is_hitting_wall,
|
||||
_wall_bounce_velocity_loss,
|
||||
)
|
||||
)
|
||||
|
||||
if is_hitting_floor:
|
||||
velocity.y = 0
|
||||
is_on_floor = true
|
||||
velocity.x = _move_speed * signf(velocity.x)
|
||||
_draw_collision_hit(pos, SIDE_BOTTOM, _floor_hit_color)
|
||||
elif is_hitting_ceiling:
|
||||
if is_hitting_ceiling:
|
||||
velocity.y = 0
|
||||
velocity.x = velocity.x / 2
|
||||
draw_rect(
|
||||
Rect2(_get_hitbox_pos(pos), _player_size),
|
||||
Color(_ceiling_hit_color, 0.25)
|
||||
)
|
||||
_draw_collision_hit(pos, SIDE_TOP, _ceiling_hit_color)
|
||||
else:
|
||||
# hitting wall
|
||||
velocity.x = -velocity.x / 2
|
||||
if is_hitting_wall:
|
||||
draw_rect(
|
||||
Rect2(_get_hitbox_pos(pos), _player_size),
|
||||
Color(_wall_hit_color, 0.25)
|
||||
|
||||
Reference in New Issue
Block a user