Midair boost, easier walljump, dpad fix, physic adjustments
This commit is contained in:
parent
7fd2c58218
commit
82028789e7
@ -62,16 +62,16 @@ window/stretch/shrink=4.5
|
||||
|
||||
move_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
|
||||
"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
jump={
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
extends Player
|
||||
|
||||
export var init_boost := false
|
||||
export var jump_buffer_filled := false
|
||||
onready var wall_touch_direction = 0
|
||||
onready var left_wall_raycasts = $WallRaycasts/LeftWallRaycast
|
||||
onready var right_wall_raycasts = $WallRaycasts/RightWallRaycast
|
||||
onready var player_state_machine = $PlayerStateMachine
|
||||
onready var init_boost = player_state_machine.init_boost
|
||||
onready var init_boost_type = player_state_machine.init_boost_type
|
||||
onready var camera_tween = $Camera2D/ShiftTween
|
||||
onready var camera = $Camera2D
|
||||
|
||||
|
||||
func _on_EnemyDetector_area_entered(area: Area2D) -> void:
|
||||
@ -83,7 +86,10 @@ func calculate_grounded_velocity(
|
||||
(
|
||||
(
|
||||
acceleration_force[state].x
|
||||
+ init_acceleration_force[state] * int(init_boost)
|
||||
+ (
|
||||
init_acceleration_force[init_boost_type]
|
||||
* int(init_boost)
|
||||
)
|
||||
)
|
||||
/ mass
|
||||
)
|
||||
@ -128,14 +134,26 @@ func is_touching_wall_completely() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
# TODO Player gets stuck to a wall easily
|
||||
func is_correct_walljump_input(direction: Vector2) -> bool:
|
||||
return (
|
||||
Input.is_action_just_pressed("jump")
|
||||
is_touching_wall_completely()
|
||||
&& Input.is_action_just_pressed("jump")
|
||||
&& abs(direction.x + wall_touch_direction) < 1
|
||||
&& abs(direction.x + wall_touch_direction) >= 0
|
||||
)
|
||||
|
||||
|
||||
func is_correct_airstrafe_input() -> bool:
|
||||
return (
|
||||
air_strafe_charges > 0
|
||||
&& (
|
||||
Input.is_action_just_pressed("move_left")
|
||||
|| Input.is_action_just_pressed("move_right")
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
func convert_velocity_to_force(velocity, mass, delta) -> float:
|
||||
return (velocity * mass) / delta
|
||||
|
||||
@ -144,20 +162,16 @@ func convert_force_to_velocity(force, mass, delta) -> float:
|
||||
return (force / mass) * delta
|
||||
|
||||
|
||||
# TODO Save this static number somewhere else
|
||||
func get_ground_friction() -> float:
|
||||
return 22.0
|
||||
|
||||
|
||||
# TODO Comments for parameters
|
||||
func calculate_deceleration_force(_gravity: float, mass: float, delta: float) -> float:
|
||||
return get_ground_friction() * _gravity * mass * delta
|
||||
return normal_floor_friction * _gravity * mass * delta
|
||||
|
||||
|
||||
func calculate_jump_velocity(
|
||||
linear_velocity: Vector2, delta: float, direction: Vector2
|
||||
) -> Vector2:
|
||||
var state = self.get_node("PlayerStateMachine").state
|
||||
var walljumping = is_correct_walljump_input(direction)
|
||||
|
||||
if (
|
||||
Input.is_action_just_pressed("jump") && state != "jump"
|
||||
@ -172,14 +186,12 @@ func calculate_jump_velocity(
|
||||
((acceleration_force[state].y + additive_jump_force) / mass)
|
||||
* -1
|
||||
)
|
||||
if (
|
||||
is_touching_wall_completely()
|
||||
&& is_correct_walljump_input(direction)
|
||||
&& ! is_on_floor()
|
||||
):
|
||||
|
||||
# TODO Das eskaliert ab und an komplett
|
||||
if walljumping && ! is_on_floor():
|
||||
# The faster you are moving up the farther the walljump goes
|
||||
linear_velocity.y = (acceleration_force["walljump"].y / mass) * -1
|
||||
linear_velocity.x += max_velocity["walljump"] * direction.x
|
||||
linear_velocity.x += acceleration_force["walljump"].x * direction.x
|
||||
|
||||
if ! Input.is_action_pressed("jump"):
|
||||
# TODO This is so good not gonna lie
|
||||
@ -194,9 +206,14 @@ func calculate_jump_velocity(
|
||||
else:
|
||||
linear_velocity.y += _gravity * delta
|
||||
|
||||
# TODO Dis shizzle buggy
|
||||
if _velocity.x == 0:
|
||||
linear_velocity.x += inair_velocity * direction.x
|
||||
|
||||
if is_correct_airstrafe_input() && ! walljumping:
|
||||
linear_velocity.x += (direction.x * acceleration_force["air_strafe"].x)
|
||||
air_strafe_charges -= 1
|
||||
|
||||
return linear_velocity
|
||||
|
||||
|
||||
@ -210,9 +227,13 @@ func calculate_fall_velocity(
|
||||
else:
|
||||
linear_velocity.y = max_velocity["fall"]
|
||||
if _velocity.x == 0:
|
||||
# TODO this is weird
|
||||
linear_velocity.x += inair_velocity * direction.x
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
jump_buffer_filled = true
|
||||
if is_correct_airstrafe_input():
|
||||
linear_velocity.x += (direction.x * acceleration_force["air_strafe"].x)
|
||||
air_strafe_charges -= 1
|
||||
return linear_velocity
|
||||
|
||||
|
||||
@ -222,13 +243,13 @@ func calculate_wallslide_velocity(
|
||||
# Walljump mechanics
|
||||
if is_correct_walljump_input(direction):
|
||||
# TODO This +0.01 indicates a larger problem with division through possible 0 values!!
|
||||
var multiplicator = max(min(1, 1000 / (_velocity.y + 0.01)), 0.5)
|
||||
var multiplicator = max(min(1, 1000 / (_velocity.y + 0.01)), 0.9)
|
||||
linear_velocity.y += (
|
||||
(acceleration_force["walljump"].y / mass)
|
||||
* -1
|
||||
* multiplicator
|
||||
)
|
||||
linear_velocity.x += max_velocity["walljump"] * direction.x
|
||||
linear_velocity.x += acceleration_force["walljump"].x * direction.x
|
||||
else:
|
||||
linear_velocity.y += _gravity * delta * 0.4
|
||||
# linear_velocity.x += inair_velocity * direction.x
|
||||
@ -241,14 +262,9 @@ func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vecto
|
||||
return out
|
||||
|
||||
|
||||
func execute_movement() -> void:
|
||||
func execute_movement(direction) -> void:
|
||||
_velocity = move_and_slide(_velocity, FLOOR_NORMAL)
|
||||
# TODO Replace .get_nodes with $ and put them to file beginning if possible
|
||||
# var camera = self.get_node("Camera2D")
|
||||
# if _velocity.x < 0:
|
||||
# camera.transform.origin.x = -100
|
||||
# if _velocity.x > 0:
|
||||
# camera.transform.origin.x = 100
|
||||
|
||||
|
||||
func die() -> void:
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://start-assets/approx mannequin.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/Actor/PlayerStateMachine.gd" type="Script" id=2]
|
||||
[ext_resource path="res://src/RayCasters/RayCaster.gd" type="Script" id=3]
|
||||
[ext_resource path="res://src/RayCasters/RayCastDebugLines.gd" type="Script" id=4]
|
||||
[ext_resource path="res://src/Actor/Blobby.gd" type="Script" id=5]
|
||||
[ext_resource path="res://src/Actor/Camera2D.gd" type="Script" id=6]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 10.6846, 20.1701 )
|
||||
@ -15,6 +14,7 @@ extents = Vector2( 11.2458, 19.4685 )
|
||||
[node name="Blobby" type="KinematicBody2D"]
|
||||
collision_mask = 8
|
||||
script = ExtResource( 5 )
|
||||
jump_buffer_filled = null
|
||||
|
||||
[node name="Player" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
@ -22,20 +22,23 @@ texture = ExtResource( 1 )
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="RayCaster" type="Node2D" parent="CollisionShape2D"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="RayCastDebugLines" type="Line2D" parent="CollisionShape2D/RayCaster"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2( 80, 0 )
|
||||
current = true
|
||||
limit_left = 0
|
||||
limit_top = 0
|
||||
limit_smoothed = true
|
||||
drag_margin_h_enabled = true
|
||||
drag_margin_v_enabled = true
|
||||
smoothing_enabled = true
|
||||
drag_margin_left = 0.08
|
||||
drag_margin_top = 0.08
|
||||
drag_margin_right = 0.08
|
||||
drag_margin_bottom = 0.07
|
||||
editor_draw_limits = true
|
||||
editor_draw_drag_margin = true
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="ShiftTween" type="Tween" parent="Camera2D"]
|
||||
|
||||
[node name="EnemyDetector" type="Area2D" parent="."]
|
||||
monitorable = false
|
||||
@ -62,7 +65,7 @@ margin_top = -34.2836
|
||||
margin_right = 25.6614
|
||||
margin_bottom = -20.2836
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "Coochie"
|
||||
text = "Ihre Werbung"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
@ -76,13 +79,13 @@ __meta__ = {
|
||||
[node name="Left_Wallcast1" type="RayCast2D" parent="WallRaycasts/LeftWallRaycast"]
|
||||
position = Vector2( -10.706, -8.03844 )
|
||||
enabled = true
|
||||
cast_to = Vector2( -1, 0 )
|
||||
cast_to = Vector2( -2, 0 )
|
||||
collision_mask = 9
|
||||
|
||||
[node name="Left_Wallcast2" type="RayCast2D" parent="WallRaycasts/LeftWallRaycast"]
|
||||
position = Vector2( -10.706, 14.8466 )
|
||||
enabled = true
|
||||
cast_to = Vector2( -1, 0 )
|
||||
cast_to = Vector2( -2, 0 )
|
||||
collision_mask = 9
|
||||
|
||||
[node name="RightWallRaycast" type="Node2D" parent="WallRaycasts"]
|
||||
@ -90,13 +93,13 @@ collision_mask = 9
|
||||
[node name="Right_Wallcast1" type="RayCast2D" parent="WallRaycasts/RightWallRaycast"]
|
||||
position = Vector2( 10.6962, -8.03844 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 1, 0 )
|
||||
cast_to = Vector2( 2, 0 )
|
||||
collision_mask = 9
|
||||
|
||||
[node name="Right_Wallcast2" type="RayCast2D" parent="WallRaycasts/RightWallRaycast"]
|
||||
position = Vector2( 10.6962, 14.8466 )
|
||||
position = Vector2( 11, 14.8466 )
|
||||
enabled = true
|
||||
cast_to = Vector2( 1, 0 )
|
||||
cast_to = Vector2( 2, 0 )
|
||||
collision_mask = 9
|
||||
|
||||
[connection signal="area_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_area_entered"]
|
||||
|
||||
31
src/Actor/Camera2D.gd
Normal file
31
src/Actor/Camera2D.gd
Normal file
@ -0,0 +1,31 @@
|
||||
extends Camera2D
|
||||
|
||||
var horizontal_facing = 0
|
||||
var camera_x_shift = 80
|
||||
|
||||
onready var prev_camera_pos = get_camera_position()
|
||||
onready var tween = $ShiftTween
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_check_facing()
|
||||
prev_camera_pos = get_camera_position()
|
||||
|
||||
|
||||
# TODO Smoothing the camera limits in godot ruins this
|
||||
func _check_facing():
|
||||
var new_h_facing = sign(get_camera_position().x - prev_camera_pos.x)
|
||||
if new_h_facing != 0 && horizontal_facing != new_h_facing:
|
||||
horizontal_facing = new_h_facing
|
||||
var target_offset = camera_x_shift * new_h_facing
|
||||
|
||||
tween.interpolate_property(
|
||||
self,
|
||||
"transform:origin:x",
|
||||
self.transform.origin.x,
|
||||
target_offset,
|
||||
1.2,
|
||||
Tween.TRANS_SINE,
|
||||
Tween.EASE_OUT
|
||||
)
|
||||
tween.start()
|
||||
@ -5,22 +5,28 @@ const FLOOR_NORMAL := Vector2.UP
|
||||
|
||||
var stomp_feedback := 1000.0
|
||||
var inair_velocity := 21
|
||||
var wallslide_threshold := 1000
|
||||
var wallslide_threshold := 300
|
||||
var normal_floor_friction := 28
|
||||
var max_velocity := {
|
||||
"walk": 130, "run": 180, "fall": 987, "walljump": 150, "idle": 130
|
||||
"walk": 120, "run": 160, "fall": 400, "walljump": 150, "idle": 120
|
||||
}
|
||||
var velocity_jump_boost_ratio := 0.1967
|
||||
# This is added to the acceleration force initially
|
||||
var init_acceleration_force := {"walk": 4181, "run": 6765, "idle": 4181}
|
||||
var init_acceleration_force := {
|
||||
"idle_walk": 4181, "idle_run": 5765, "walk_run": 1000
|
||||
}
|
||||
# newtonmeters is the unit
|
||||
var acceleration_force := {
|
||||
"walk": Vector2(2584, 2200),
|
||||
"idle": Vector2(2584, 2200),
|
||||
"run": Vector2(2584, 2200),
|
||||
"walljump": Vector2(2548, 2200)
|
||||
"walk": Vector2(2000, 1800),
|
||||
"idle": Vector2(2000, 1800),
|
||||
"run": Vector2(2000, 1800),
|
||||
"walljump": Vector2(130, 1800),
|
||||
"air_strafe": Vector2(60, 0)
|
||||
}
|
||||
var _gravity := 1667.0
|
||||
var _gravity := 1111.0
|
||||
# Kilograms
|
||||
var mass := 6
|
||||
var mass := 6.5
|
||||
|
||||
var _velocity := Vector2.ZERO
|
||||
|
||||
var air_strafe_charges := 1
|
||||
|
||||
@ -2,6 +2,8 @@ extends StateMachine
|
||||
|
||||
onready var coyoteTimer = $CoyoteTimer
|
||||
export var coyote_hanging = false
|
||||
export var init_boost = false
|
||||
export var init_boost_type = "idle_walk"
|
||||
onready var jumpBufferTimer = $JumpBufferTimer
|
||||
|
||||
|
||||
@ -13,7 +15,7 @@ func _ready():
|
||||
add_state("jump")
|
||||
add_state("fall")
|
||||
add_state("wallslide")
|
||||
print_debug(states)
|
||||
state = states.idle
|
||||
set_state(states.idle)
|
||||
|
||||
|
||||
@ -46,38 +48,46 @@ func _state_logic(delta):
|
||||
_:
|
||||
print("don't panik")
|
||||
|
||||
parent._velocity = handle_input_ref.call_func(delta)
|
||||
parent.execute_movement()
|
||||
var direction = get_horizontal_direction()
|
||||
|
||||
parent._velocity = handle_input_ref.call_func(delta, direction)
|
||||
parent.execute_movement(direction)
|
||||
|
||||
|
||||
func handle_idle_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_idle_input(delta, direction) -> Vector2:
|
||||
if Input.is_action_pressed("boost_move"):
|
||||
return parent.handle_grounded_movement(delta, direction)
|
||||
else:
|
||||
return parent.handle_grounded_movement(delta, direction)
|
||||
|
||||
|
||||
func handle_walk_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_walk_input(delta, direction) -> Vector2:
|
||||
return parent.handle_grounded_movement(delta, direction)
|
||||
|
||||
|
||||
func handle_run_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_run_input(delta, direction) -> Vector2:
|
||||
return parent.handle_grounded_movement(delta, direction)
|
||||
|
||||
|
||||
func handle_jump_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_jump_input(delta, direction) -> Vector2:
|
||||
return parent.handle_jump_movement(delta, direction)
|
||||
|
||||
|
||||
func handle_fall_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_fall_input(delta, direction) -> Vector2:
|
||||
return parent.handle_fall_movement(delta, direction)
|
||||
|
||||
|
||||
func handle_wallslide_input(delta, direction := get_horizontal_direction()) -> Vector2:
|
||||
func handle_wallslide_input(delta, direction) -> Vector2:
|
||||
return parent.handle_wallslide_movement(delta, direction)
|
||||
|
||||
|
||||
func get_horizontal_direction() -> Vector2:
|
||||
#TODO Check if this is fixed yet
|
||||
if Input.get_connected_joypads().size() > 0:
|
||||
if Input.is_joy_button_pressed(Input.get_connected_joypads()[0], 14):
|
||||
return Vector2(-1, 0)
|
||||
if Input.is_joy_button_pressed(Input.get_connected_joypads()[0], 15):
|
||||
return Vector2(1, 0)
|
||||
return Vector2(
|
||||
(
|
||||
Input.get_action_strength("move_right")
|
||||
@ -136,15 +146,33 @@ func _get_transition(delta):
|
||||
coyote_hanging = false
|
||||
if new_state != self.state:
|
||||
return new_state
|
||||
parent.init_boost = false
|
||||
init_boost = false
|
||||
return null
|
||||
|
||||
|
||||
func _enter_state(new_state, old_state):
|
||||
if new_state == "run" || "walk":
|
||||
parent.init_boost = true
|
||||
if old_state == "run" && new_state == "walk":
|
||||
parent.init_boost = false
|
||||
if old_state == "idle" && new_state == "walk" || new_state == "run":
|
||||
init_boost = true
|
||||
init_boost_type = old_state + "_" + new_state
|
||||
if old_state == "walk" && new_state == "run":
|
||||
init_boost = true
|
||||
init_boost_type = old_state + "_" + new_state
|
||||
if (
|
||||
["fall", "jump", "wallslide"].has(old_state)
|
||||
&& ["idle", "walk", "run"].has(new_state)
|
||||
):
|
||||
parent.air_strafe_charges = 1
|
||||
# if old_state == "run" && new_state == "walk":
|
||||
# init_boost = false
|
||||
|
||||
# TODO This may be hard to keep track of if many states are added
|
||||
# if (old_state != "run" || "walk" || "idle") && parent.is_on_floor():
|
||||
# emit_signal("got_grounded")
|
||||
# if (
|
||||
# (old_state == "run" || "walk" || "idle" || "wallslide")
|
||||
# && ! parent.is_on_floor()
|
||||
# ):
|
||||
# emit_signal("got_ungrounded")
|
||||
|
||||
|
||||
func _exit_state(old_state, new_state):
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user