I
I
ikeky2020-05-29 11:19:20
Unity
ikeky, 2020-05-29 11:19:20

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

1 answer(s)
I
ikeky, 2020-05-29
@ikeky

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();
                }
            }

I will close this topic, maybe it will be useful to you someday.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question