Movement Parameters now used to aid fetching and merging of state movements
This commit is contained in:
parent
ec869ed1cc
commit
6d51eaffb0
32
lib/classes/movement_parameters.gd
Normal file
32
lib/classes/movement_parameters.gd
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
class_name MovementParameters
|
||||||
|
extends Reference
|
||||||
|
|
||||||
|
## Vector based ones for x and y
|
||||||
|
export var base_move_speed :Vector2
|
||||||
|
export var base_move_acceleration :Vector2
|
||||||
|
export var move_speed_modifier :Vector2
|
||||||
|
export var move_speed_modifier_acceleration :Vector2
|
||||||
|
|
||||||
|
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
var jerk: float = 0.0
|
||||||
|
# export var base_h_move_speed :float
|
||||||
|
# export var base_h_move_acceleration :float
|
||||||
|
# export var h_move_speed_modifier :float
|
||||||
|
# export var h_move_modifier_move_acceleration :float
|
||||||
|
|
||||||
|
# export var base_v_move_speed :float
|
||||||
|
# export var base_v_move_acceleration :float
|
||||||
|
# export var v_move_speed_modifier :float
|
||||||
|
# export var v_move_modifier_move_acceleration :float
|
||||||
|
|
||||||
|
func modify(_movement_parameters :MovementParameters):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# var movement_params :Dictionary = {
|
||||||
|
# "_base_h_move_speed" : _state.horizontal_speed,
|
||||||
|
# "_base_h_move_acceleration" : _state.horizontal_acceleration,
|
||||||
|
# "_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
|
||||||
|
# "_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
|
||||||
|
# "_jerk_factor" : _state.jerk_factor,
|
||||||
|
# "_gravity" : _state.gravity
|
||||||
|
# }
|
||||||
|
|
@ -149,14 +149,16 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
_movement_override_normal := Vector2(0,0),
|
_movement_override_normal := Vector2(0,0),
|
||||||
_velocity_override := Vector2(0,0)) -> Vector2:
|
_velocity_override := Vector2(0,0)) -> Vector2:
|
||||||
## Calculated movement speed.
|
## Calculated movement speed.
|
||||||
var movement_params :Dictionary = {
|
# var movement_params :Dictionary = {
|
||||||
"_base_h_move_speed" : _state.horizontal_speed,
|
# "_base_h_move_speed" : _state.horizontal_speed,
|
||||||
"_base_h_move_acceleration" : _state.horizontal_acceleration,
|
# "_base_h_move_acceleration" : _state.horizontal_acceleration,
|
||||||
"_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
|
# "_base_h_move_speed_modifier" : _state.horizontal_speed_offset,
|
||||||
"_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
|
# "_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration,
|
||||||
"_jerk_factor" : _state.jerk_factor,
|
# "_jerk_factor" : _state.jerk_factor,
|
||||||
"_gravity" : _state.gravity
|
# "_gravity" : _state.gravity
|
||||||
}
|
# }
|
||||||
|
var movement_parameters :MovementParameters = _state.get_movement_parameters()
|
||||||
|
|
||||||
var calc_velocity = Vector2.ZERO
|
var calc_velocity = Vector2.ZERO
|
||||||
if _velocity_override.x != 0.0:
|
if _velocity_override.x != 0.0:
|
||||||
calc_velocity.x = _velocity_override.x
|
calc_velocity.x = _velocity_override.x
|
||||||
|
|
@ -181,7 +183,7 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
# but if a modifier applies, or an accelleration is given.
|
# but if a modifier applies, or an accelleration is given.
|
||||||
# an entirely differant process occurs.
|
# an entirely differant process occurs.
|
||||||
##
|
##
|
||||||
var h_speed = resolve_h_speed(movement_params)
|
var h_speed = resolve_h_speed(movement_parameters)
|
||||||
#if h_speed != Vector2.ZERO:
|
#if h_speed != Vector2.ZERO:
|
||||||
# pass
|
# pass
|
||||||
## If an override has been passed (we're ignoring input direction
|
## If an override has been passed (we're ignoring input direction
|
||||||
|
|
@ -192,7 +194,7 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
|
move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector)
|
||||||
|
|
||||||
## Which direction will acceleration be applied.
|
## Which direction will acceleration be applied.
|
||||||
calc_acceleration.x = resolve_h_acceleration(movement_params, calc_velocity, move_direction.x)
|
calc_acceleration.x = resolve_h_acceleration(movement_parameters, calc_velocity, move_direction.x)
|
||||||
|
|
||||||
## Direction of inertia not equal to move direction
|
## Direction of inertia not equal to move direction
|
||||||
## If inertia is applying in a direction
|
## If inertia is applying in a direction
|
||||||
|
|
@ -258,7 +260,7 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
## Neutralize the inertia? but how?
|
## Neutralize the inertia? but how?
|
||||||
## Recalc the acceleration with inertia
|
## Recalc the acceleration with inertia
|
||||||
#var friction :Vector2
|
#var friction :Vector2
|
||||||
calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
calc_friction.x = resolve_h_acceleration(movement_parameters,Vector2(calc_inertia.x, h_speed.x), move_direction.x)
|
||||||
if calc_friction.x != 0.0: ## No dapening acceleration applies
|
if calc_friction.x != 0.0: ## No dapening acceleration applies
|
||||||
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
|
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta))
|
||||||
## Apply friction
|
## Apply friction
|
||||||
|
|
@ -282,7 +284,7 @@ func new_move_actor_as_desired(_delta :float,
|
||||||
## For now, y component of velocity is just gravity
|
## For now, y component of velocity is just gravity
|
||||||
#calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
|
#calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y
|
||||||
|
|
||||||
calc_inertia.y += movement_params["_gravity"] * _delta
|
calc_inertia.y += movement_parameters.gravity * _delta
|
||||||
calc_velocity.y = calc_inertia.y
|
calc_velocity.y = calc_inertia.y
|
||||||
|
|
||||||
## calc x component of felicty
|
## calc x component of felicty
|
||||||
|
|
@ -321,23 +323,23 @@ func apply_movement_to_parent( _velocity :Vector2) -> void:
|
||||||
|
|
||||||
|
|
||||||
## Returns an Vector where x is MIN_SPEED and y is MAX_SPEED
|
## Returns an Vector where x is MIN_SPEED and y is MAX_SPEED
|
||||||
func resolve_h_speed(_params :Dictionary) -> Vector2:
|
func resolve_h_speed(_params :MovementParameters) -> Vector2:
|
||||||
var base_speed :float = _params["_base_h_move_speed"]
|
var base_speed :float = _params.base_move_speed.x
|
||||||
## if a speed difference applies
|
## if a speed difference applies
|
||||||
if _params["_base_h_move_speed_modifier"] != 0:
|
if _params.move_speed_modifier.x != 0:
|
||||||
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
|
var speed_differance = base_speed + _params.move_speed_modifier.x
|
||||||
|
|
||||||
return(Vector2(base_speed, speed_differance))
|
return(Vector2(base_speed, speed_differance))
|
||||||
return Vector2(base_speed,base_speed)
|
return Vector2(base_speed,base_speed)
|
||||||
|
|
||||||
func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direction :float) -> float:
|
func resolve_h_acceleration(_params :MovementParameters, _inertia :Vector2, _move_direction :float) -> float:
|
||||||
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
||||||
## if a speed difference applies
|
## if a speed difference applies
|
||||||
var _acceleration :float = 0.0
|
var _acceleration :float = 0.0
|
||||||
var base_speed :float = _params["_base_h_move_speed"]
|
var base_speed :float = _params.base_move_speed.x
|
||||||
if _params["_base_h_move_speed_modifier"] != 0:
|
if _params.move_speed_modifier.x != 0:
|
||||||
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
|
var speed_differance = base_speed + _params.move_speed_modifier.x
|
||||||
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
|
_acceleration = _params.base_move_acceleration.x + _params.move_speed_modifier_acceleration.x
|
||||||
##WIP: Add part where offset acceleration only applies until the inertia equals the offset or whatever
|
##WIP: Add part where offset acceleration only applies until the inertia equals the offset or whatever
|
||||||
# if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
|
# if sign(_params["_base_h_move_modifier_move_acceleration"]) == -1 and abs(_inertia.x) >= speed_differance:
|
||||||
# #print("I should add the modifier acceleration maybe?")
|
# #print("I should add the modifier acceleration maybe?")
|
||||||
|
|
@ -345,7 +347,7 @@ func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direct
|
||||||
# else:
|
# else:
|
||||||
# print ("not yet.")
|
# print ("not yet.")
|
||||||
else:
|
else:
|
||||||
_acceleration = _params["_base_h_move_acceleration"]
|
_acceleration = _params.base_move_acceleration.x
|
||||||
|
|
||||||
## This works but I want to try something differant.
|
## This works but I want to try something differant.
|
||||||
# if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
|
# if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction):
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,12 @@ func enter() -> void:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
func get_movement_parameters() -> MovementParameters:
|
||||||
|
var movement_parameters = MovementParameters.new()
|
||||||
|
movement_parameters.base_move_speed.x = horizontal_speed
|
||||||
|
movement_parameters.base_move_acceleration.x = horizontal_acceleration
|
||||||
|
movement_parameters.move_speed_modifier.x = horizontal_speed_offset
|
||||||
|
movement_parameters.move_speed_modifier_acceleration.x = horizontal_speed_offset_acceleration
|
||||||
|
|
||||||
|
return movement_parameters
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Interactables/HealthPickup.gd"
|
"path": "res://src/Interactables/HealthPickup.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Area2D",
|
||||||
"class": "Interactable",
|
"class": "Interactable",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://lib/templates/Interactable/Interactable.gd"
|
"path": "res://lib/templates/Interactable/Interactable.gd"
|
||||||
|
|
@ -89,6 +89,11 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/classes/movement_component.gd"
|
"path": "res://src/classes/movement_component.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Reference",
|
||||||
|
"class": "MovementParameters",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://lib/classes/movement_parameters.gd"
|
||||||
|
}, {
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "Movement_StateReceiver",
|
"class": "Movement_StateReceiver",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
|
@ -171,6 +176,7 @@ _global_script_class_icons={
|
||||||
"LevelTransition": "",
|
"LevelTransition": "",
|
||||||
"Modifier_Receiver": "",
|
"Modifier_Receiver": "",
|
||||||
"MovementComponent": "",
|
"MovementComponent": "",
|
||||||
|
"MovementParameters": "",
|
||||||
"Movement_StateReceiver": "",
|
"Movement_StateReceiver": "",
|
||||||
"PlayerData": "",
|
"PlayerData": "",
|
||||||
"Projectile": "",
|
"Projectile": "",
|
||||||
|
|
@ -401,6 +407,10 @@ dash_2={
|
||||||
common/enable_pause_aware_picking=true
|
common/enable_pause_aware_picking=true
|
||||||
2d/default_gravity=600
|
2d/default_gravity=600
|
||||||
|
|
||||||
|
[mono]
|
||||||
|
|
||||||
|
project/assembly_name="Attempt 2"
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
2d/default_gravity=280
|
2d/default_gravity=280
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user