- Home /
Quaternion.LookRotation in 2D game issue
Hi!
I've been searching for a very long time for the answer to my problem on the internet, but I've had no luck. I'm relatively new to unity in the sense that this is my first big game. The problem is I am trying to make my enemy attack the player using a fireball. I used transform.rotation = Quaternion.LookRotation(playerPos);
to make the fireball face the player and transform.position += transform.forward * speed * Time.deltaTime
to make it go towards the player. The problem is the y axis rotates to -90, so we can't see the sprite anymore. I tried adding the sprite in the children of my gameobject and fireball.transform.Rotate(transform.position.x, 90, transform.position.z)
, but I realised that that function just rotates the sprite 90 degrees, so my fireball just ends up going beyblade. I tried lateupdating transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, 0, transform.localEulerAngles.z);
and using this instead of the Quaternion.LookRotation code above transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x,0, transform.rotation.eulerAngles.z);
or transform.right = playerPos.position - transform.position;
.
I am completely lost and help would be greatly appreciated. Thank you!
Your answer
Follow this Question
Related Questions
Rotating by 90 degrees eventually locks 2 Answers
Adding quaternions using a seperate axis 0 Answers
How to store direction so that player faces last direction when joystick is idle 2 Answers
Rotating an Object in Update Function 1 Answer
translate a gameobjects position.y based on another gameobjects position .z 1 Answer