- Home /
Target Lookat not working . I want Z axis to rotate only.
Hello. Right now , i am practicing making a 2D shooting game.
I want to make the enemy look at the Player by simply using Lookat program, but it only rotates for x ,y axis, which the 2D sprites looks winded up. (as i look at the transform tab, it seems the y axis rotates seems to set to 90degrees.)
I do not know why this is happening. I just want the enemy to rotate ony for Z axis Could someone kindly help me how i could fix this issue??
Heres the code i have written down. its quite simple.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class chase : MonoBehaviour {
public Transform target;
void Update(){
transform.LookAt (target, Vector3.right);
}
}
Answer by SFoxx28 · Jan 20, 2018 at 04:15 AM
Vector3.right is the same as Vector3(1,0,0) which is the x axis.
I'm not familiar with 2D game creation in Unity but try Vector3.forward which is the same as Vector3(0,0,1).
I'm assuming you are using all 3 axis in your game which is why you need a Vector3 in the first place. Generally 2D games only use the X and Y axis, although depending on your game it can use a 3D environment if you want it to.
Answer by rashea · Jan 20, 2018 at 08:00 AM
Thanks for your kind reply. I have tried the Vector3.forward but didnt solve the problem.
The x axis moves only, and the y& z axis rotates -90degree.
Your answer
Follow this Question
Related Questions
Trying to make an enemy fire at the player 1 Answer
Unity 5 Platform Effector 2D Bug or Not 0 Answers
Attacking Enemies at an Angle 0 Answers
How can i fix this shooting code in a 2D plane? 0 Answers
Dictionary in second script empty 1 Answer