diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index b24b8a3..9afe3c2 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -146,7 +146,8 @@ func _on_state_change(old_state_name:String, new_state :State): var debug_speed_tracker :Vector2 func new_move_actor_as_desired(_delta :float, _state :StateAnimatedActor, - _movement_override_normal := Vector2(0,0)) -> Vector2: + _movement_override_normal := Vector2(0,0), + _velocity_override := Vector2(0,0)) -> Vector2: ## Calculated movement speed. var movement_params :Dictionary = { "_base_h_move_speed" : _state.horizontal_speed, @@ -159,7 +160,12 @@ func new_move_actor_as_desired(_delta :float, var calc_velocity = Vector2.ZERO var calc_acceleration = Vector2.ZERO var calc_inertia :Vector2 - calc_inertia.x = abs(velocity.x) + ##TODO: make sure velocity variable exists since we rely on it + ## 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. calc_inertia.y = velocity.y var calc_inertial_dir = Vector2(sign(velocity.x),sign(velocity.y)) @@ -182,20 +188,20 @@ func new_move_actor_as_desired(_delta :float, 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 ## If inertia is applying in a direction - if calc_inertial_dir.x: - ## And it doesn't apply in the same direction as our movement direction - if calc_inertial_dir.x != sign(move_direction.x): - ## 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 +# if calc_inertial_dir.x: +# ## And it doesn't apply in the same direction as our movement direction +# if calc_inertial_dir.x != sign(move_direction.x): +# ## 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 @@ -217,10 +223,13 @@ func new_move_actor_as_desired(_delta :float, 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 = 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 = 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) @@ -240,13 +249,15 @@ func new_move_actor_as_desired(_delta :float, 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 ## Move back towards the base speed - calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_acceleration.x * _delta)) -# if calc_inertia.x > h_speed.x: -# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), -# calc_inertia.x, h_speed.x) -# else: -# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), -# h_speed.x, calc_inertia.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, h_speed.x) + else: + calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), + h_speed.x, calc_inertia.x) else: ## No longer applying acceleration ## Neutralize the inertia? but how? ## Recalc the acceleration with inertia @@ -342,7 +353,7 @@ func resolve_h_speed(_params :Dictionary) -> Vector2: # return Vector2(0,inertia) return Vector2(base_speed,base_speed) -func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float: +func resolve_h_acceleration(_params :Dictionary, _inertia :Vector2, _move_direction :float) -> float: ## TODO: Adjust for jerk, determine if we're currently experiencing accel ## if a speed difference applies var _acceleration :float = 0.0 @@ -350,17 +361,21 @@ func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_directio _acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] else: _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) ## Well this didn't work #_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] - - #return _acceleration - - if _speed.x < _speed.y: + ## If the indented movedirection doesn't match our velocity direction + + if _inertia.x != 0.0 and sign(_inertia.x) != sign(_move_direction): + return _acceleration * -1 + elif sign(_move_direction) != 0: + ## If no velocity or it matches just return as is. return _acceleration - elif _speed.x > _speed.y: - return _acceleration * -1 + + # No accel returned unless intended return 0.0 func resolve_move_direction(_momentum :Vector2, diff --git a/src/actors/players/playerE/states/roll.tres b/src/actors/players/playerE/states/roll.tres index bd34015..b1dce7e 100644 --- a/src/actors/players/playerE/states/roll.tres +++ b/src/actors/players/playerE/states/roll.tres @@ -12,6 +12,6 @@ name = "roll" horizontal_speed = 150.0 horizontal_acceleration = 1.36422e-12 horizontal_speed_offset = -140.0 -horizontal_speed_offset_acceleration = 50.0 +horizontal_speed_offset_acceleration = -50.0 jerk_factor = 0.0 animation_sequence = [ "roll" ]