Switch to transformed based flip on kinimatic body instead of sprite based one so gun and positions offset appropriately. I wish I knew this when I started. More improvements can be done here so I don't have to update the code in every state.
This commit is contained in:
parent
f6cb10fce5
commit
a7bc6c6349
|
|
@ -144,7 +144,7 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||||
position = Vector2( 81, 27 )
|
position = Vector2( 136, 35 )
|
||||||
|
|
||||||
[node name="CameraControl" type="Position2D" parent="."]
|
[node name="CameraControl" type="Position2D" parent="."]
|
||||||
process_priority = 1
|
process_priority = 1
|
||||||
|
|
|
||||||
|
|
@ -92,14 +92,12 @@ ui_accept={
|
||||||
move_left_1={
|
move_left_1={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
|
|
||||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
move_right_1={
|
move_right_1={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
|
|
||||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
var velocity = Vector2(0,0)
|
var velocity = Vector2(0,0)
|
||||||
var direction = Vector2(0,0)
|
var direction = Vector2(-1,0)
|
||||||
|
|
||||||
export var player_number: int = 1
|
export var player_number: int = 1
|
||||||
|
|
||||||
|
|
@ -29,16 +29,22 @@ func _physics_process(delta: float) -> void:
|
||||||
# #TODO: So much hack
|
# #TODO: So much hack
|
||||||
# if direction.x != 0:
|
# if direction.x != 0:
|
||||||
# gun.set_scale( Vector2(direction.x,1))
|
# gun.set_scale( Vector2(direction.x,1))
|
||||||
if direction.x < 0:
|
|
||||||
var t = Transform2D()
|
# Commented out to try parent transforms instead
|
||||||
# Translation
|
# if direction.x < 0:
|
||||||
t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
|
# var t = Transform2D()
|
||||||
gun.transform = t
|
# # Translation
|
||||||
elif direction.x > 0:
|
# t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
|
||||||
var t = Transform2D()
|
# gun.transform = t
|
||||||
# Translation
|
# elif direction.x > 0:
|
||||||
t.origin = Vector2(gun.offset_position.x, gun.offset_position.y)
|
# var t = Transform2D()
|
||||||
gun.transform = t
|
# # Translation
|
||||||
|
# t.origin = Vector2(gun.offset_position.x, gun.offset_position.y)
|
||||||
|
# gun.transform = t
|
||||||
|
|
||||||
|
# Attempting a Kinematic2D level scale for flip operations instead.
|
||||||
|
#self.transform
|
||||||
|
#self.scale.x = -1
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
movement_state_machine.process_frame(delta)
|
movement_state_machine.process_frame(delta)
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,12 @@ func process_physics(delta: float) -> State:
|
||||||
parent.direction.x = -1
|
parent.direction.x = -1
|
||||||
|
|
||||||
|
|
||||||
if move_component.flipped_sprite == true:
|
if move_component.flipped_sprite == false:
|
||||||
animations.flip_h = parent.direction.x > 0
|
#parent.scale.x = parent.direction.x * -1
|
||||||
|
parent.transform.x.x = parent.direction.x * -1 # -1
|
||||||
else:
|
else:
|
||||||
animations.flip_h = parent.direction.x < 0
|
#parent.scale.x = parent.direction.x
|
||||||
|
parent.transform.x.x = parent.direction.x # 1
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
if parent.velocity.x == 0:
|
if parent.velocity.x == 0:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
extends State
|
extends State
|
||||||
|
|
||||||
|
var debugTimeTracker := 0.0
|
||||||
|
|
||||||
export (NodePath) var jump_node
|
export (NodePath) var jump_node
|
||||||
export (NodePath) var fall_node
|
export (NodePath) var fall_node
|
||||||
export (NodePath) var move_node
|
export (NodePath) var move_node
|
||||||
|
|
@ -35,6 +37,11 @@ func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
|
debugTimeTracker += delta
|
||||||
|
if debugTimeTracker > 2:
|
||||||
|
debugTimeTracker = 0.0
|
||||||
|
print("DEBUG TRANSFORM:", parent.transform)
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
parent.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
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,12 @@ func process_physics(delta: float) -> State:
|
||||||
elif parent.velocity.x < 0:
|
elif parent.velocity.x < 0:
|
||||||
parent.direction.x = -1
|
parent.direction.x = -1
|
||||||
|
|
||||||
if move_component.flipped_sprite == true:
|
if move_component.flipped_sprite == false:
|
||||||
animations.flip_h = parent.direction.x > 0
|
#parent.scale.x = parent.direction.x * -1
|
||||||
|
parent.transform.x.x = parent.direction.x * -1 # -1
|
||||||
else:
|
else:
|
||||||
animations.flip_h = parent.direction.x < 0
|
#parent.scale.x = parent.direction.x
|
||||||
|
parent.transform.x.x = parent.direction.x # 1
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
if parent.velocity.x == 0:
|
if parent.velocity.x == 0:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
extends State
|
extends State
|
||||||
|
|
||||||
|
var debugTimeTracker := 0.0
|
||||||
|
|
||||||
export (NodePath) var jump_node
|
export (NodePath) var jump_node
|
||||||
export (NodePath) var fall_node
|
export (NodePath) var fall_node
|
||||||
export (NodePath) var idle_node
|
export (NodePath) var idle_node
|
||||||
|
|
@ -22,6 +24,10 @@ func process_input(_event: InputEvent) -> State:
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
# if move_component.wants_jump() and parent.is_on_floor():
|
# if move_component.wants_jump() and parent.is_on_floor():
|
||||||
# return jump_state
|
# return jump_state
|
||||||
|
debugTimeTracker += delta
|
||||||
|
if debugTimeTracker > 2:
|
||||||
|
debugTimeTracker = 0.0
|
||||||
|
print("DEBUG TRANSFORM:", parent.transform)
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
parent.velocity.y += gravity * delta
|
||||||
|
|
||||||
|
|
@ -46,10 +52,19 @@ func process_physics(delta: float) -> State:
|
||||||
parent.direction.x = -1
|
parent.direction.x = -1
|
||||||
|
|
||||||
|
|
||||||
if move_component.flipped_sprite == true:
|
# if move_component.flipped_sprite == true:
|
||||||
animations.flip_h = parent.direction.x > 0
|
# animations.flip_h = parent.direction.x > 0
|
||||||
|
# else:
|
||||||
|
# animations.flip_h = parent.direction.x < 0
|
||||||
|
# Attempting to flip based on scale instead of sprite flip so that
|
||||||
|
# all children nodes get flipped as well:
|
||||||
|
if move_component.flipped_sprite == false:
|
||||||
|
#parent.scale.x = parent.direction.x * -1
|
||||||
|
parent.transform.x.x = parent.direction.x * -1 # -1
|
||||||
else:
|
else:
|
||||||
animations.flip_h = parent.direction.x < 0
|
#parent.scale.x = parent.direction.x
|
||||||
|
parent.transform.x.x = parent.direction.x # 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Another approach of changing state based on actual achieved velocity
|
# Another approach of changing state based on actual achieved velocity
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user