I have a following script for the pet to follow the player but I don’t know how to make it so that the pet will turn around when going in the other direction so it goes in the wrong direction does anyone have a code that can help.
You could add a check to the follow script. lastPosition - newPosition to find the direction it is traveling then update facing to match.
lastPosition.x equal 2 and newPosition.x equal 1 then difference would equal 1 so if lastPosition - newPosition positive then we are traveling left.
lastPosition.x equal 1 and newPosition.x equal 2 then difference would equal -1 so if lastPosition - newPosition negative then we are traveling right.
Can you wright that in script i’m new to coding
Not going to learn if someone writes everything for you and would be hard to do considering I’m not working on your project and can’t know exactly how to apply the logic I gave you. But you can apply that logic to work for you and increase your capacity for further changes in the future.
Just google it “2D Unity Object follow” and you should get plenty of info. Try YouTube, you can find so much there on the subject and they will walk you through it. Adehm is right, most people here won’t just write code for you unless you show that you have tried yourself. Aka, post your code, tell us what you have done, what is currently happening and what you want to happen. Maybe then someone will add a few lines of code to get you back in the right direction.