I've been working on the code for the front character-faced cursor, but I have a problem with the code.
You'll see the problem in this video.
Some how, when character going further from the center, more further cursor needs to trigger the character to trigger a flip event.
Here the code I'm use
The code for cursor event
if get_local_mouse_position() > self.global_position:
Character.scale.x = 1
else:
Character.scale.x = -1
Full code
extends KinematicBody2D
const UP_DIRECTION := Vector2.UP
export var speed := 600.0
export var jump_strength := 2000
export var maximum_jumps := 2
export var double_jump_strength := 2000
export var gravity := 4500.0
var _jumps_made := 0
var _velocity := Vector2.ZERO
onready var Character : Node2D = $TestModelSkin
onready var _animation_player : AnimationPlayer = $TestModelSkin/AnimationPlayer
func _physics_process(delta: float) -> void:
var _horizontal_direction =(
Input.get_action_strength("move_right")
- Input.get_action_strength("move_left")
)
_velocity.x = _horizontal_direction * speed
_velocity.y += gravity * delta
var is_falling := _velocity.y > 0.0 and not is_on_floor()
var is_jumping := Input.is_action_just_pressed("jump") and is_on_floor()
var is_double_jumping := Input.is_action_just_pressed("jump") and is_falling
var is_jump_cancelled := Input.is_action_just_released("jump") and _velocity.y < 0.0
var is_idling := is_on_floor() and is_zero_approx(_velocity.x)
var is_running := is_on_floor() and not is_zero_approx(_velocity.x)
if is_jumping:
_jumps_made += 1
_velocity.y = -jump_strength
elif is_double_jumping:
_jumps_made += 1
if _jumps_made <= maximum_jumps:
_velocity.y = -double_jump_strength
elif is_jump_cancelled:
_velocity.y = 0.0
elif is_idling or is_running:
_jumps_made = 0
_velocity = move_and_slide(_velocity, UP_DIRECTION)
_velocity = move_and_slide(_velocity, UP_DIRECTION)
if is_jumping or is_double_jumping:
_animation_player.play("Jump")
elif is_running:
_animation_player.play("Run")
elif is_idling:
_animation_player.play("Rest")
if get_local_mouse_position() > self.global_position:
Character.scale.x = 1
else:
Character.scale.x = -1