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
10309056d0
commit
8f67de539c
|
|
@ -144,7 +144,7 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 81, 27 )
|
||||
position = Vector2( 136, 35 )
|
||||
|
||||
[node name="CameraControl" type="Position2D" parent="."]
|
||||
process_priority = 1
|
||||
|
|
|
|||
|
|
@ -92,14 +92,12 @@ ui_accept={
|
|||
move_left_1={
|
||||
"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)
|
||||
, 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)
|
||||
]
|
||||
}
|
||||
move_right_1={
|
||||
"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)
|
||||
, 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)
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
var velocity = Vector2(0,0)
|
||||
var direction = Vector2(0,0)
|
||||
var direction = Vector2(-1,0)
|
||||
|
||||
export var player_number: int = 1
|
||||
|
||||
|
|
@ -29,16 +29,22 @@ func _physics_process(delta: float) -> void:
|
|||
# #TODO: So much hack
|
||||
# if direction.x != 0:
|
||||
# gun.set_scale( Vector2(direction.x,1))
|
||||
if direction.x < 0:
|
||||
var t = Transform2D()
|
||||
# Translation
|
||||
t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
|
||||
gun.transform = t
|
||||
elif direction.x > 0:
|
||||
var t = Transform2D()
|
||||
# Translation
|
||||
t.origin = Vector2(gun.offset_position.x, gun.offset_position.y)
|
||||
gun.transform = t
|
||||
|
||||
# Commented out to try parent transforms instead
|
||||
# if direction.x < 0:
|
||||
# var t = Transform2D()
|
||||
# # Translation
|
||||
# t.origin = Vector2(gun.offset_position.x * -1, gun.offset_position.y)
|
||||
# gun.transform = t
|
||||
# elif direction.x > 0:
|
||||
# var t = Transform2D()
|
||||
# # 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:
|
||||
movement_state_machine.process_frame(delta)
|
||||
|
|
|
|||
|
|
@ -30,10 +30,12 @@ func process_physics(delta: float) -> State:
|
|||
parent.direction.x = -1
|
||||
|
||||
|
||||
if move_component.flipped_sprite == true:
|
||||
animations.flip_h = parent.direction.x > 0
|
||||
if move_component.flipped_sprite == false:
|
||||
#parent.scale.x = parent.direction.x * -1
|
||||
parent.transform.x.x = parent.direction.x * -1 # -1
|
||||
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.velocity.x == 0:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
extends State
|
||||
|
||||
var debugTimeTracker := 0.0
|
||||
|
||||
export (NodePath) var jump_node
|
||||
export (NodePath) var fall_node
|
||||
export (NodePath) var move_node
|
||||
|
|
@ -35,6 +37,11 @@ func process_input(_event: InputEvent) -> State:
|
|||
return null
|
||||
|
||||
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 = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||
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:
|
||||
parent.direction.x = -1
|
||||
|
||||
if move_component.flipped_sprite == true:
|
||||
animations.flip_h = parent.direction.x > 0
|
||||
if move_component.flipped_sprite == false:
|
||||
#parent.scale.x = parent.direction.x * -1
|
||||
parent.transform.x.x = parent.direction.x * -1 # -1
|
||||
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.velocity.x == 0:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
extends State
|
||||
|
||||
var debugTimeTracker := 0.0
|
||||
|
||||
export (NodePath) var jump_node
|
||||
export (NodePath) var fall_node
|
||||
export (NodePath) var idle_node
|
||||
|
|
@ -22,6 +24,10 @@ func process_input(_event: InputEvent) -> State:
|
|||
func process_physics(delta: float) -> State:
|
||||
# if move_component.wants_jump() and parent.is_on_floor():
|
||||
# return jump_state
|
||||
debugTimeTracker += delta
|
||||
if debugTimeTracker > 2:
|
||||
debugTimeTracker = 0.0
|
||||
print("DEBUG TRANSFORM:", parent.transform)
|
||||
|
||||
parent.velocity.y += gravity * delta
|
||||
|
||||
|
|
@ -46,10 +52,19 @@ func process_physics(delta: float) -> State:
|
|||
parent.direction.x = -1
|
||||
|
||||
|
||||
if move_component.flipped_sprite == true:
|
||||
animations.flip_h = parent.direction.x > 0
|
||||
# if move_component.flipped_sprite == true:
|
||||
# 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:
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user