Moved velocity into movement component. Hope I don't regret it.

This commit is contained in:
Nitsud Yarg 2024-06-02 13:09:48 -07:00
parent d50e3f6a51
commit 8597840033
10 changed files with 35 additions and 34 deletions

View File

@ -1,7 +1,7 @@
class_name Actor
extends KinematicBody2D
var velocity = Vector2(0,0)
#var velocity = Vector2(0,0)
#var direction = Vector2(-1,0)
export(String, "Player", "Enemy", "NPC") var actor_type

View File

@ -16,10 +16,10 @@ func process_input(_event: InputEvent) -> State:
return null
func process_physics(delta: float) -> State:
parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
# if parent.velocity.x != 0.0:
# parent.direction.x = parent.velocity.x
@ -34,7 +34,7 @@ func process_physics(delta: float) -> State:
# parent.transform.x.x = parent.direction.x # 1
if parent.is_on_floor():
if parent.velocity.x == 0:
if move_component.velocity.x != 0:
return move_state
return idle_state
return null

View File

@ -47,12 +47,12 @@ func process_physics(delta: float) -> State:
parent.shoot_projectile()
can_fire = false
parent.velocity.y += gravity * delta
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.y += gravity * delta
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if parent.velocity.x != 0.0:
if move_component.velocity.x != 0.0:
return move_state
if !parent.is_on_floor():

View File

@ -15,7 +15,7 @@ onready var fire_state: State = get_node(fire_node)
func enter() -> void:
.enter()
parent.set_hurtbox(true)
parent.velocity.x = 0
move_component.velocity.x = 0
func process_input(_event: InputEvent) -> State:
# if get_jump() and parent.is_on_floor():
@ -43,12 +43,12 @@ func process_physics(delta: float) -> State:
debugTimeTracker = 0.0
print(owner.name, " DEBUG TRANSFORM:", parent.transform)
parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if parent.velocity.x != 0.0:
if move_component.velocity.x != 0.0:
return move_state
if !parent.is_on_floor():

View File

@ -13,7 +13,7 @@ export var jump_force: float = 900.0
func enter() -> void:
.enter()
parent.velocity.y = -jump_force
move_component.velocity.y = -jump_force
func process_input(_event: InputEvent) -> State:
move_component.get_movement_direction()
@ -21,13 +21,13 @@ func process_input(_event: InputEvent) -> State:
func process_physics(delta: float) -> State:
parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
if parent.velocity.y > 0:
if move_component.velocity.y > 0:
return fall_state
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if move_component.get_movement_direction() != 0.0:
parent.transform.x.x = move_component.get_movement_direction()
@ -40,7 +40,7 @@ func process_physics(delta: float) -> State:
# parent.transform.x.x = parent.direction.x # 1
if parent.is_on_floor():
if parent.velocity.x == 0:
if move_component.velocity.x == 0:
return move_state
return idle_state

View File

@ -30,7 +30,7 @@ func process_physics(delta: float) -> State:
debugTimeTracker = 0.0
print("DEBUG TRANSFORM:", parent.transform)
parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
# var movement = move_component.get_movement_direction() * move_speed
#
@ -41,10 +41,10 @@ func process_physics(delta: float) -> State:
# parent.velocity.x = movement
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if parent.velocity.x == 0.0:
if move_component.velocity.x == 0.0:
return idle_state
if move_component.get_movement_direction() != 0.0:

View File

@ -103,8 +103,8 @@ func process_physics(_delta: float) -> State:
# animation_index += 1
func move_actor_as_desired(delta: float):
parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))

View File

@ -5,10 +5,11 @@ export (NodePath) var idle_node
onready var idle_state: State = get_node(idle_node)
func process_physics(delta: float) -> State:
parent.velocity.y += gravity * delta
#parent.velocity.y += gravity * delta
move_component.velocity.y += gravity * delta
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if move_component.get_movement_direction() != 0.0:
parent.transform.x.x = move_component.get_movement_direction()

View File

@ -9,7 +9,7 @@ onready var move_state: State = get_node(move_node)
func enter() -> void:
.enter()
# parent.set_hurtbox(true)
parent.velocity.x = 0
move_component.velocity.x = 0
if debug_state:
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
@ -22,7 +22,7 @@ func process_physics(delta: float) -> State:
move_actor_as_desired(delta)
if parent.velocity.x != 0.0:
if move_component.velocity.x != 0.0:
return move_state
if !parent.is_on_floor():

View File

@ -10,7 +10,7 @@ func process_physics(delta: float) -> State:
move_actor_as_desired(delta)
if parent.velocity.x == 0.0:
if move_component.velocity.x == 0.0:
return idle_state
#Flip the character before tha actual move maybe.