Attempt at making grounded movement work well
This commit is contained in:
parent
5f17289426
commit
825bc032da
25
Player.gd
25
Player.gd
@ -63,8 +63,13 @@ func _physics_process(delta):
|
|||||||
# Make movement local
|
# Make movement local
|
||||||
move_acceleration = transform.basis * move_acceleration
|
move_acceleration = transform.basis * move_acceleration
|
||||||
|
|
||||||
|
print(on_ground)
|
||||||
|
|
||||||
# Jumping and Gravity
|
# Jumping and Gravity
|
||||||
var gravity_acceleration = get_node(solar_system).get_gravitation_acceleration(transform.origin)
|
var gravity_acceleration = get_node(solar_system).get_gravitation_acceleration(transform.origin)
|
||||||
|
#if on_ground:
|
||||||
|
# FIXME: This breaks some things, but seems to be the right principle
|
||||||
|
#gravity_acceleration = Vector3.ZERO
|
||||||
|
|
||||||
apply_acceleration((move_acceleration + gravity_acceleration) * delta)
|
apply_acceleration((move_acceleration + gravity_acceleration) * delta)
|
||||||
|
|
||||||
@ -80,17 +85,21 @@ func _physics_process(delta):
|
|||||||
time_since_jump_start += delta
|
time_since_jump_start += delta
|
||||||
|
|
||||||
# Apply movement to position
|
# Apply movement to position
|
||||||
# FIXME: move_and_slide might make more sense, but couldn't quite get that to work...
|
velocity = move_and_slide(velocity, -gravity_acceleration.normalized(), true)
|
||||||
#move_and_slide(velocity, -gravity_acceleration.normalized(), true)
|
on_ground = false
|
||||||
var collision = move_and_collide(velocity * delta)
|
|
||||||
|
if get_slide_count() > 0:
|
||||||
|
var collision = get_slide_collision(0)
|
||||||
|
|
||||||
if collision:
|
|
||||||
if collision.collider.is_in_group("MovingPlatform"):
|
if collision.collider.is_in_group("MovingPlatform"):
|
||||||
# Inherit the moving platform's velocity
|
# Inherit the moving platform's velocity and apply the initial velocity
|
||||||
current_target_velocity = collision.collider.velocity
|
if current_target_velocity != collision.collider.velocity / 6.0:
|
||||||
velocity = current_target_velocity
|
current_target_velocity = collision.collider.velocity / 6.0
|
||||||
|
velocity = current_target_velocity
|
||||||
if not jumping:
|
if not jumping:
|
||||||
on_ground = true
|
# Check the collision normal and set to grounded if it's close to the player's up vector
|
||||||
|
if collision.normal.dot(global_transform.basis.y) > 0.5: # an angle of >45° counts as grounded
|
||||||
|
on_ground = true
|
||||||
else:
|
else:
|
||||||
# We're not colliding with anything, so drag takes us towards 0
|
# We're not colliding with anything, so drag takes us towards 0
|
||||||
current_target_velocity = Vector3.ZERO
|
current_target_velocity = Vector3.ZERO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user