Lockon system doesn't get position from array

Godot Version 4.1.3

Solved

Question: How to get position of an enemy charcater body from an array

How to get position of a character body from an array? cause it doesn’t work for me I will send the screen shot but in short:
I set area 3d to detetct player when enters and put enemy (self) into a global array


and I go to player script where lockon system is writeen and I set target pos as enemy_onspot array


:exclamation: The problem is: it says the property transform doesn’t exist and when I add [0] it says out of border

The problem, I think, is you failed to consider what happens if you call Lockon() while the globl.enemy_onspot array is empty. That’s why you get an “out of bounds” error. You can check with globl.enemy_onspot.is_empty() before attempting to index into the array.

1 Like

Someone on discord helped me with it it got fixed

Yeah you are right I did similar thing to check
if !array.size() > 0:
Return
.
It worked and it was good :+1: thanks to that person on godot discord server that told me
And thank you :heart:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.