Jump to content

help on C# in unity.

Johanes
public GameObject TargetCube;
    // Start is called before the first frame update
    void Start()
    {
        // transform.LookAt(TargetCube.transform);
        // Quaternion q, q1;

        // q = Quaternion.AngleAxis(90.0f, Vector3.up);
        // q1 = Quaternion.AngleAxis(90.0f, Vector3.right);

        // transform.rotation = q * q1;

        Vector3 toOther = TargetCube.transform.position - transform.position;
        toOther.Normalize();
        Vector3 axis = Vector3.Cross(Vector3.forward, toOther);

        float angle = Mathf.Acos(Vector3.Dot(Vector3.forward, toOther));
        Quaternion q = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, axis);

        transform.rotation = q;

    }

    // Update is called once per frame
    void Update()
    {
        
    }

For now the code that i have a hard time understanding is 


 Vector3 toOther = TargetCube.transform.position - transform.position;
 

i understand is that this code is making a Vector3 Variable and storing the TargetCube.transform.position (minus) transform.position.. but what is transform.position where is it getting the number to minus with TargetCube.transform.position.

Is it getting the position of the Gameobject that i had the script attach to??

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Johanes said:

Is it getting the position of the Gameobject that i had the script attach to??

Yes.

You're setting toOther to be whatever the result of targetCubes position minus the current GameObjects position is.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×