Hi, I'm making a Beholder Enemy that uses a Statemachine.
Basicly The Beholder will have a secondary Sprite (an eye) that tracks the Players movement. The Beholder will have states like Chase and Attack. The eye will track the player in both of these states.
I'm relatively new to programming but i have heard you want to avoid copy-pasting code when possible. So because i want the tracking functionality in multiple states should i make the function that tracks the players movement in the Beholders main script?
Also when in the Attack state i want the eye that's tracking the player to shoot a laser, so i guess the functionality would differ a bit in each state? Not sure how to set everything up in a good way.
If i go the route of placing the tracking logic in the main script, do i want to call the tracking function that's in the main script separately in each state?
Or would i make an if-statement in the main script saying like
if statemachine.state == attack or statemachine.state == chase
Then track player.
Maybe something like this would work?
Help is very much appreciated Thanks!