Z
Z
Zitrid2021-08-23 22:35:09
C++ / C#
Zitrid, 2021-08-23 22:35:09

The object is spinning near the center, not in the center, how to fix this?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class slcamera : MonoBehaviour
{
    public float offset;

    void Update()
    {
        Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; ;
        float rotateZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0f, 0f, rotateZ + offset);


    }
}


I'm just starting to study units, the code is taken from the Internet, and is almost not understood by me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yura Mailler, 2021-08-25
@Yura111

I advise you to first study or finish your studies if you don’t understand the C# unity code, well, or C# itself if you don’t know it, since there is nowhere to develop without it. I can advise a free course from
ANDROIDHELPER
But still, about your question, I will make a test project with your code and the object (3D object) will spin quietly
, standing in place, maybe this is not what you wanted to achieve, if so, explain in more detail what do you want to achieve

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question