# Character look at mouse position
if playerTarget == null:
rayHit.y = player.translation.y
player.look_at(rayHit, Vector3.UP)
# Character look at target
else:
mouseTarget = playerTarget.transform.origin
mouseTarget.y += 1.5
player.look_at(mouseTarget, Vector3.UP)
gun.look_at(mouseTarget, Vector3.UP)
This is supposed to check if the mouse is pointed at an enemy. If so, player looks at enemy, if not, it just looks at the mouse position. Problem is every now and then, when testing the game, i get a null instance error after killing an enemy saying that playerTarget cant be found because its a null. Any ways to fix this?