Compare commits

..

No commits in common. "ad01724071b1587a4fbd68a5d65b6a1de36c004a" and "00de0d64501fa285110889a52f02969388f82356" have entirely different histories.

7 changed files with 43 additions and 96 deletions

View File

@ -2,7 +2,7 @@
[ext_resource path="res://src/classes/camera_guide.gd" type="Script" id=1] [ext_resource path="res://src/classes/camera_guide.gd" type="Script" id=1]
[ext_resource path="res://src/Camera2D.gd" type="Script" id=2] [ext_resource path="res://src/Camera2D.gd" type="Script" id=2]
[ext_resource path="res://src/levels/TestBox.tscn" type="PackedScene" id=3] [ext_resource path="res://src/levels/CloneBox.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4] [ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/ui/HUD.tscn" type="PackedScene" id=5] [ext_resource path="res://src/ui/HUD.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Main.gd" type="Script" id=7] [ext_resource path="res://src/Main.gd" type="Script" id=7]

View File

@ -146,8 +146,7 @@ func _on_state_change(old_state_name:String, new_state :State):
var debug_speed_tracker :Vector2 var debug_speed_tracker :Vector2
func new_move_actor_as_desired(_delta :float, func new_move_actor_as_desired(_delta :float,
_state :StateAnimatedActor, _state :StateAnimatedActor,
_movement_override_normal := Vector2(0,0), _movement_override_normal := 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,
@ -160,12 +159,7 @@ func new_move_actor_as_desired(_delta :float,
var calc_velocity = Vector2.ZERO var calc_velocity = Vector2.ZERO
var calc_acceleration = Vector2.ZERO var calc_acceleration = Vector2.ZERO
var calc_inertia :Vector2 var calc_inertia :Vector2
##TODO: make sure velocity variable exists since we rely on it calc_inertia.x = abs(velocity.x)
## Calc from the _velocity_override instead of current object velocity
if _velocity_override.x != 0.0:
calc_inertia.x = abs(_velocity_override.x)
else:
calc_inertia.x = abs(velocity.x)
##TODO: Only implemented horizontal so far. ##TODO: Only implemented horizontal so far.
calc_inertia.y = velocity.y calc_inertia.y = velocity.y
var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y)) var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y))
@ -187,25 +181,13 @@ func new_move_actor_as_desired(_delta :float,
else: else:
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. calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x)
calc_acceleration.x = resolve_h_acceleration(movement_params, 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 calc_inertial_dir.x:
# if calc_inertial_dir.x: if calc_inertial_dir.x != sign(move_direction.x):
# ## And it doesn't apply in the same direction as our movement direction ## flip the direction of acceleration
# if calc_inertial_dir.x != sign(move_direction.x): calc_acceleration.x *= -1
# ## Apply the direction of acceleration and apply as friction
# # Friction allows the inertia to trend toward 0 instead of the
# # 'To' direction of speed.
# ##
# #calc_friction.x = calc_acceleration.x * -1
# calc_friction.x = calc_acceleration.x
# calc_acceleration.x = 0.0
## We are always moving from h_speed.x towards y at a given rate
## if we have a difference of speed ## if we have a difference of speed
if h_speed.x != h_speed.y: if h_speed.x != h_speed.y:
@ -213,26 +195,8 @@ func new_move_actor_as_desired(_delta :float,
## Clamp inertia to in between speed. ## Clamp inertia to in between speed.
# Problem is that we can suddenly gain or lose inertia. # Problem is that we can suddenly gain or lose inertia.
## ##
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# h_speed.x , h_speed.y) h_speed.x , h_speed.y)
## If there is currently no inertia apply the base h_speed
if calc_inertia.x == 0.0:
calc_inertia.x = h_speed.x
## Apply acceleration
if h_speed.y > h_speed.x:
calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta))
else:
## use of move_toward forcing need to apply negative accel as postitive.
#calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta))
calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
h_speed.y , h_speed.x)
var foo = 3
## Apply friction
#calc_inertia.x = move_toward(calc_inertia.x, 0, (calc_friction.x * _delta))
# calc_inertia.x = clamp( calc_inertia.x + (calc_friction.x * _delta),
# 0 , h_speed.y)
## Disable this for now hopefully inertial acceleration flip removes this ## Disable this for now hopefully inertial acceleration flip removes this
## Update: it mostly did. Going to keep this here for a while though. ## Update: it mostly did. Going to keep this here for a while though.
@ -248,11 +212,7 @@ func new_move_actor_as_desired(_delta :float,
# calc_inertia.x, h_speed.y) # calc_inertia.x, h_speed.y)
elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement
if calc_acceleration.x != 0.0: # We are applying acceleration if calc_acceleration.x != 0.0: # We are applying acceleration
## Move back towards the base speed if calc_inertia.x > h_speed.x:
# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta),
# h_speed.x , h_speed.y)
if calc_inertia.x < h_speed.x:
calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta),
calc_inertia.x, h_speed.x) calc_inertia.x, h_speed.x)
else: else:
@ -264,13 +224,12 @@ func new_move_actor_as_desired(_delta :float,
#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_params,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)) if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down)
# if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down) calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
# calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), h_speed.x, calc_inertia.x)
# h_speed.x, calc_inertia.x) else: ## Inertia lower than base speed (we need to catch up)
# else: ## Inertia lower than base speed (we need to catch up) calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta),
# calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), calc_inertia.x, h_speed.x)
# calc_inertia.x, h_speed.x)
else: else:
## no residual acceleration (friction) applies, kill the momentum ## no residual acceleration (friction) applies, kill the momentum
calc_inertia.x = 0.0 calc_inertia.x = 0.0
@ -307,7 +266,7 @@ func new_move_actor_as_desired(_delta :float,
#calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) #calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') +
"H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + "H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) +
"\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) + "\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) +
"\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) + "\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) +
"\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) + "\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) +
@ -335,25 +294,17 @@ func resolve_h_speed(_params :Dictionary) -> Vector2:
if _params["_base_h_move_speed_modifier"] != 0: if _params["_base_h_move_speed_modifier"] != 0:
var speed_differance = base_speed + _params["_base_h_move_speed_modifier"] var speed_differance = base_speed + _params["_base_h_move_speed_modifier"]
# if sign(_params["_base_h_move_speed_modifier"]) == -1:
# return Vector2(speed_differance, base_speed)
# else:
# return Vector2(base_speed, speed_differance)
return(Vector2(base_speed, speed_differance))
## We start at a slower base speed and move upward ## We start at a slower base speed and move upward
## Disabled because flipping accel direction may make more sense. if speed_differance > base_speed:
# if speed_differance > base_speed: return(Vector2(base_speed, speed_differance))
# return(Vector2(base_speed, speed_differance)) else:
# else: ## We start at a higher speed and move downward to base
# ## We start at a higher speed and move downward to base return(Vector2(speed_differance, base_speed ))
# return(Vector2(speed_differance, base_speed ))
# if inertia: # if inertia:
# return Vector2(0,inertia) # return Vector2(0,inertia)
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 :Dictionary, _speed :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
@ -361,21 +312,15 @@ func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direct
_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] _acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
else: else:
_acceleration = _params["_base_h_move_acceleration"] _acceleration = _params["_base_h_move_acceleration"]
##TODO: Add part where offset acceleration only applies until the inertia equals the offset or whatever
#_acceleration *= sign(_move_direction) #_acceleration *= sign(_move_direction)
## Well this didn't work ## Well this didn't work
#_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] #_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"]
## If the indented movedirection doesn't match our velocity direction
if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction): if _speed.x < _speed.y:
return _acceleration * -1
elif sign(_move_direction) != 0:
## If no velocity or it matches just return as is.
return _acceleration return _acceleration
elif _speed.x > _speed.y:
# No accel returned unless intended return _acceleration * -1
return 0.0 return 0.0
func resolve_move_direction(_momentum :Vector2, func resolve_move_direction(_momentum :Vector2,
@ -389,6 +334,9 @@ func resolve_move_direction(_momentum :Vector2,
return Vector2(horizontal_movement_direction,0) return Vector2(horizontal_movement_direction,0)
func adjust_base_movement():
pass
## About to DEPR this one for redesigned one above ## About to DEPR this one for redesigned one above
func move_actor_as_desired( x_move_direction_override: float = 0): func move_actor_as_desired( x_move_direction_override: float = 0):
var delta:float = physics_delta var delta:float = physics_delta

View File

@ -218,8 +218,7 @@ func _state_process_physics_roll():
# Force role in facing direction # Force role in facing direction
# instead of movement direction # instead of movement direction
#move_actor_as_desired(parent.transform.x.x) move_actor_as_desired(parent.transform.x.x)
apply_movement_to_parent(new_move_actor_as_desired( physics_delta , current_state, parent.transform.x ))
if !parent.is_on_floor(): if !parent.is_on_floor():
#return fall_state #return fall_state

View File

@ -10,7 +10,7 @@ debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "idle" name = "idle"
horizontal_speed = 1.36422e-12 horizontal_speed = 1.36422e-12
horizontal_acceleration = -2.0 horizontal_acceleration = 0.0
horizontal_speed_offset = 0.0 horizontal_speed_offset = 0.0
horizontal_speed_offset_acceleration = 0.0 horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0 jerk_factor = 0.0

View File

@ -9,9 +9,9 @@ script = ExtResource( 1 )
debug_state = false debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "move" name = "move"
horizontal_speed = 10.0 horizontal_speed = 90.0
horizontal_acceleration = 20.0 horizontal_acceleration = 10.0
horizontal_speed_offset = 80.0 horizontal_speed_offset = -90.0
horizontal_speed_offset_acceleration = 0.0 horizontal_speed_offset_acceleration = 0.0
jerk_factor = 0.0 jerk_factor = 0.0
animation_sequence = [ "run" ] animation_sequence = [ "run" ]

View File

@ -9,9 +9,9 @@ script = ExtResource( 1 )
debug_state = false debug_state = false
timeout_seconds = 0.0 timeout_seconds = 0.0
name = "roll" name = "roll"
horizontal_speed = 150.0 horizontal_speed = 10.0
horizontal_acceleration = 1.36422e-12 horizontal_acceleration = 1.36422e-12
horizontal_speed_offset = -140.0 horizontal_speed_offset = 150.0
horizontal_speed_offset_acceleration = -50.0 horizontal_speed_offset_acceleration = -150.0
jerk_factor = 0.0 jerk_factor = 0.0
animation_sequence = [ "roll" ] animation_sequence = [ "roll" ]

File diff suppressed because one or more lines are too long