Moved velocity into movement component. Hope I don't regret it.
This commit is contained in:
parent
d50e3f6a51
commit
8597840033
|
|
@ -1,7 +1,7 @@
|
||||||
class_name Actor
|
class_name Actor
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
var velocity = Vector2(0,0)
|
#var velocity = Vector2(0,0)
|
||||||
#var direction = Vector2(-1,0)
|
#var direction = Vector2(-1,0)
|
||||||
|
|
||||||
export(String, "Player", "Enemy", "NPC") var actor_type
|
export(String, "Player", "Enemy", "NPC") var actor_type
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
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
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
# if parent.velocity.x != 0.0:
|
# if parent.velocity.x != 0.0:
|
||||||
# parent.direction.x = parent.velocity.x
|
# parent.direction.x = parent.velocity.x
|
||||||
|
|
@ -34,7 +34,7 @@ func process_physics(delta: float) -> State:
|
||||||
# parent.transform.x.x = parent.direction.x # 1
|
# parent.transform.x.x = parent.direction.x # 1
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
if parent.velocity.x == 0:
|
if move_component.velocity.x != 0:
|
||||||
return move_state
|
return move_state
|
||||||
return idle_state
|
return idle_state
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,12 @@ func process_physics(delta: float) -> State:
|
||||||
parent.shoot_projectile()
|
parent.shoot_projectile()
|
||||||
can_fire = false
|
can_fire = false
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
move_component.velocity.y += gravity * delta
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
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
|
return move_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ onready var fire_state: State = get_node(fire_node)
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
parent.set_hurtbox(true)
|
parent.set_hurtbox(true)
|
||||||
parent.velocity.x = 0
|
move_component.velocity.x = 0
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_input(_event: InputEvent) -> State:
|
||||||
# if get_jump() and parent.is_on_floor():
|
# if get_jump() and parent.is_on_floor():
|
||||||
|
|
@ -43,12 +43,12 @@ func process_physics(delta: float) -> State:
|
||||||
debugTimeTracker = 0.0
|
debugTimeTracker = 0.0
|
||||||
print(owner.name, " DEBUG TRANSFORM:", parent.transform)
|
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 = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
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
|
return move_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export var jump_force: float = 900.0
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
parent.velocity.y = -jump_force
|
move_component.velocity.y = -jump_force
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_input(_event: InputEvent) -> State:
|
||||||
move_component.get_movement_direction()
|
move_component.get_movement_direction()
|
||||||
|
|
@ -21,13 +21,13 @@ func process_input(_event: InputEvent) -> State:
|
||||||
|
|
||||||
|
|
||||||
func process_physics(delta: float) -> 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
|
return fall_state
|
||||||
|
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.transform.x.x = move_component.get_movement_direction()
|
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
|
# parent.transform.x.x = parent.direction.x # 1
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
if parent.velocity.x == 0:
|
if move_component.velocity.x == 0:
|
||||||
return move_state
|
return move_state
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func process_physics(delta: float) -> State:
|
||||||
debugTimeTracker = 0.0
|
debugTimeTracker = 0.0
|
||||||
print("DEBUG TRANSFORM:", parent.transform)
|
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
|
# 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.x = movement
|
||||||
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
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
|
return idle_state
|
||||||
|
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ func process_physics(_delta: float) -> State:
|
||||||
# animation_index += 1
|
# animation_index += 1
|
||||||
|
|
||||||
func move_actor_as_desired(delta: float):
|
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 = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@ export (NodePath) var idle_node
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
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
|
move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
parent.transform.x.x = move_component.get_movement_direction()
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ onready var move_state: State = get_node(move_node)
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
# parent.set_hurtbox(true)
|
# parent.set_hurtbox(true)
|
||||||
parent.velocity.x = 0
|
move_component.velocity.x = 0
|
||||||
if debug_state:
|
if debug_state:
|
||||||
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
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)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
if parent.velocity.x != 0.0:
|
if move_component.velocity.x != 0.0:
|
||||||
return move_state
|
return move_state
|
||||||
|
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
move_actor_as_desired(delta)
|
move_actor_as_desired(delta)
|
||||||
|
|
||||||
if parent.velocity.x == 0.0:
|
if move_component.velocity.x == 0.0:
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
#Flip the character before tha actual move maybe.
|
#Flip the character before tha actual move maybe.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user