Hi I want to make object look at the mouse
this is kinda 2D game with top view on object, so I want object to turn around y axis ONLY and look atmouse position
This is the code I did, object looks at mouse position, but It is rotating around x and z axis so that spoils it’s movement
void Update ()
{
RaycastHit mousehit;
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out mousehit))
{
target = mousehit.point;
target.y = transform.position.y;
bject.transform.LookAt(target);
[COLOR="red"]bject.transform.Rotate.z(0);
bject.transform.Rotate.x(0);[/COLOR]
}
}
this colored in red is something that I’ve tried to write as a fix but it doesn’t work like this.
is read only, it’s not function for changing value.
(all it does is returns your x or z angle)
and novashot I tryed to remake my code and mix it with yours but it doesn’t works,
then I made new script, copied your code and pasted it and I attached that script on my player object but it doesn’t work
I’m sorry but I’m not too good with C.
can you tell me which part should I change or explain me your code, my camera is not attached on players object, and it’s distance with ground is y = 75
my 1st code worked fine but I wanted rotation around y axis ONLY
my object was rotating around all axis