How do I change the position of my player model after I rotate it so it's not teleporting?
I am new to Unity/C# and I know that this question has been done to death, but no matter what answers I look up, none work for me! I should also preface that the code I'm using is tied together with copy & pasted code from a handful of tutorials. I'm working with a horizontal-facing voxel model that is modeled after a 2D sprite in order to give it a shadow and give it a 2.5D look (similar to an Octopath Traveler sprite).
I've figured out how to turn the sprite around so it's facing left or the right, however, it teleports towards the new direction it's facing whenever it turns it around. How do I make my model stay in it's original place while it turns from left to right or vise-versa? Here is my rotation coding so far:
{
public KeyCode pressLeft;
public KeyCode pressRight;
void Start(){
}
public bool isFacingLeft;
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
isFacingLeft = true;
}
if (Input.GetKey(KeyCode.RightArrow))
{
isFacingLeft = false;
}
Flip();
}
void Flip()
{
if (isFacingLeft ==true)
{
transform.localEulerAngles = new Vector3(0, 0, 0);
}
if (isFacingLeft ==false)
{
transform.localEulerAngles = new Vector3(0, 180, 0);
}
}
}
If there is no issue with the rotation code and you need to see my movement code, just ask.
Where I said "turn the sprite around" I meant "turn the model around."
Your answer
Follow this Question
Related Questions
Enemy not facing player when enter rotation orbit 0 Answers
Transform.Rotate not working around certain axes 1 Answer
How to get the position of the Main Camera 0 Answers
How to rotate a camera slowly along a tween? 1 Answer
My camera is moving away from the object it's rotating around, how do I fix this? 0 Answers