problem getting player to release enemy from grab

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chris33556

as you can see in the gif above . when the player grabs the enemy from the front side , to release the player , one pushes opposite direction . this works fine . However , im having difficulty doing the same when grabbing the enemy from the rear. i cant get the player to release enemy by pushing right (opposite direction) . here is a demo showing the problem

heres the player code :

extends KinematicBody

onready var AnimSprite = $AnimatedSprite3D

var facing_direction = Vector3.RIGHT

var velocity = Vector3()
var speed = 3
var isAttacking = false
var input_vector = Vector3.ZERO
onready var AttackArea = $AttackArea
var target_enemy
var player_timer
var isWalking = true
var PlayerStunned = true
var isGrabbing = true

enum states {
IDLE
WALK
PLAYERSTUNNED
GRABBING
}

var state = states.IDLE

func _ready():
target_enemy = get_tree().current_scene.get_node(“enemy”)
#AttackArea.connect(“body_entered”, self, “_on_Player_area_entered”)
func _on_PlayerTimer_timeout():
print(“Player timer has timed out!”)

func _physics_process(delta):
update_animation()
get_input()
flip_dir()

func flip_dir():
if velocity.x > 0:
facing_direction = Vector3.RIGHT
AnimSprite.scale.x = 1
print(“facing right”)
elif velocity.x < 0:
facing_direction = Vector3.RIGHT
AnimSprite.scale.x = -1
print(“facing left”)

func get_input():
if not isAttacking:
if target_enemy.state != target_enemy.states.GRABBED:
isGrabbing = false
if isWalking:
velocity.x = speed * Input.get_axis(“ui_left”, “ui_right”)
velocity.z = speed * Input.get_axis(“ui_up”, “ui_down”)
state = states.WALK

			if velocity.x == 0 and velocity.z == 0:
				state = states.IDLE
				isAttacking = false
				
	if target_enemy.state == target_enemy.states.GRABBED:
		if Input.is_action_just_pressed("ui_left"):
			state = states.GRABBING
			target_enemy.state = target_enemy.states.RELEASED
			isGrabbing = false
			facing_direction = Vector3.LEFT if AnimSprite.scale.x > 0 else Vector3.RIGHT
			
velocity = move_and_slide(velocity, Vector3.UP)
var motion = velocity.normalized() * speed

func update_animation():
match state:
states.IDLE:
$AnimatedSprite3D.play(“idle”)
states.WALK:
$AnimatedSprite3D.play(“walking”)

	states.GRABBING:
		$AnimatedSprite3D.play("grabbing")
		velocity = Vector3.ZERO

func _on_AttackArea_area_entered(area):
if area.is_in_group(“frontbody”):
state = states.GRABBING

elif area.is_in_group("rearbody"):
	state = states.GRABBING

Try formatting your code again as it became garbled by the editor.
And perhaps consider to explain what you’ve tried already to fix the issue.

Dri | 2023-04-18 13:45