Updates
This commit is contained in:
parent
ffba3fce8c
commit
7093b218fa
16 changed files with 215 additions and 69 deletions
70
player.gd
70
player.gd
|
@ -1,17 +1,14 @@
|
|||
extends CharacterBody2D
|
||||
extends RigidBody2D
|
||||
|
||||
@export var speed = 300.0
|
||||
@export var jump_velocity = -400.0
|
||||
@export var wall_jump_velocity = 600.0
|
||||
@export var ungrounded_x_lerp = 10.0
|
||||
@export var grounded_drag_lerp = 5.0
|
||||
@export var ungrounded_drag_lerp = 5.0
|
||||
@export var fox_time = 5
|
||||
@export var limp_gravity_modifier = 2.0
|
||||
@export var on_ground_force = 50.0
|
||||
@export var in_air_force = 10.0
|
||||
@export var stop_force = 10.0
|
||||
|
||||
var x_velocity_offset = 0
|
||||
var x_movement = 0
|
||||
var desired_x_movement = 0
|
||||
var last_grounded = 0
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
|
@ -29,42 +26,53 @@ func _ready():
|
|||
$Sprite2D.modulate = Color.from_hsv((username_hash % 255) / 255.0, 0.5, 0.8)
|
||||
gun = $Gun
|
||||
|
||||
func _physics_process(delta):
|
||||
func _physics_process(_delta):
|
||||
if $MultiplayerSynchronizer.get_multiplayer_authority() != multiplayer.get_unique_id():
|
||||
return
|
||||
|
||||
# Add the gravity.
|
||||
if is_on_floor():
|
||||
var is_on_floor = len($FloorDetect.get_overlapping_bodies()) > 0
|
||||
if is_on_floor:
|
||||
last_grounded = Time.get_ticks_msec()
|
||||
else:
|
||||
velocity.y += gravity * delta * (limp_gravity_modifier if Input.is_action_pressed("limp") else 1.0)
|
||||
gravity_scale = limp_gravity_modifier if Input.is_action_pressed("limp") else 1.0
|
||||
|
||||
gun.look_at(get_global_mouse_position())
|
||||
|
||||
var grounded = Time.get_ticks_msec() - last_grounded < fox_time
|
||||
|
||||
var on_left_wall = len($WallDetectLeft.get_overlapping_bodies()) > 0
|
||||
var on_right_wall = len($WallDetectRight.get_overlapping_bodies()) > 0
|
||||
var on_wall = on_left_wall or on_right_wall
|
||||
|
||||
x_velocity_offset = lerpf(x_velocity_offset, 0, (grounded_drag_lerp if is_on_floor() else ungrounded_drag_lerp) * delta)
|
||||
|
||||
# Handle Jump.
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
if grounded:
|
||||
velocity.y = jump_velocity
|
||||
elif len($WallDetect.get_overlapping_bodies()) > 0:
|
||||
velocity.y = jump_velocity
|
||||
if $WallDetect.get_overlapping_bodies()[0].position.x > position.x:
|
||||
x_velocity_offset = -wall_jump_velocity
|
||||
else:
|
||||
x_velocity_offset = wall_jump_velocity
|
||||
#velocity_offset = velocity_offset.lerp(Vector2.ZERO, (grounded_drag_lerp if is_on_floor() else ungrounded_drag_lerp) * delta)
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction = Input.get_axis("move_left", "move_right")
|
||||
velocity.x = x_velocity_offset
|
||||
if direction:
|
||||
desired_x_movement = direction * speed;
|
||||
x_movement = lerpf(x_movement, desired_x_movement, 1 if grounded else ungrounded_x_lerp * delta)
|
||||
velocity.x += x_movement
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
if grounded:
|
||||
apply_central_force(Vector2.RIGHT * direction * speed * on_ground_force)
|
||||
if direction == 0:
|
||||
if linear_velocity.x > 0.1:
|
||||
apply_central_force(Vector2.LEFT * stop_force)
|
||||
elif linear_velocity.x < 0.1:
|
||||
apply_central_force(Vector2.RIGHT * stop_force)
|
||||
elif (not on_wall) or (on_left_wall && direction > 0) or (on_right_wall and direction < 0):
|
||||
apply_central_force(Vector2.RIGHT * direction * speed * in_air_force)
|
||||
|
||||
if linear_velocity.x > speed:
|
||||
linear_velocity.x = speed
|
||||
elif linear_velocity.x < -speed:
|
||||
linear_velocity.x = -speed
|
||||
|
||||
move_and_slide()
|
||||
# Handle Jump.
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
if grounded:
|
||||
apply_central_impulse(Vector2.UP * jump_velocity)
|
||||
$JumpSound.play()
|
||||
if not grounded and on_wall:
|
||||
apply_central_impulse(Vector2.UP * jump_velocity)
|
||||
if on_right_wall:
|
||||
apply_central_impulse(Vector2.LEFT * wall_jump_velocity)
|
||||
else:
|
||||
apply_central_impulse(Vector2.RIGHT * wall_jump_velocity)
|
||||
$JumpSound.play()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue