Answer the question
In order to leave comments, you need to log in
How to make a circular motion in unity?
I tried to make a circular motion in the unit
but the cursor constantly cannot rotate the object more than 90 degrees
https://www.youtube.com/watch?v=JidMgS4gaK8&featur...
Here is the code:
Y = Input.mousePosition.y;
X = Input.mousePosition.x;
posX = Mathf.Cos(Mathf.Atan2(transform.localPosition.x / 2 - Y, transform.localPosition.z / 2 - X)) * radius;
posY = Mathf.Sin(Mathf.Atan2(transform.localPosition.x / 2 - Y, transform.localPosition.z / 2 - X)) * radius;
Coll.localPosition = new Vector3(posY,0,posX);
Answer the question
In order to leave comments, you need to log in
Unexpectedly, I found a way out of this situation. I went for a completely different approach: I used raycasts and used transform.lookat
Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if(groundPlane.Raycast(cameraRay, out rayLength)){
Vector3 pointToLook = cameraRay.GetPoint(rayLength);
transform.LookAt(new Vector3(pointToLook.x,transform.position.y, pointToLook.z));
if(Input.GetMouseButtonUp (0)){
transform.position = Coll.position;
EndFishkaEvent();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question