Wednesday, September 14, 2022
HomeGame Developmentunity - Methods to change the rotation level of an object in...

unity – Methods to change the rotation level of an object in code?


I am attempting to create a minimap for my sport in Unity. It consists of a 2D picture sprite inside a masks. I’ve obtained the rotation and the motion throughout the masks down, however the one drawback is the truth that the picture rotates round its central level, as an alternative of the central level of the masks, which is the place the participant is.
Is there any option to repair this in code or utilizing parenting or one thing? Any assistance is appreciated.

Code for the picture:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;

public class UIMinimap : MonoBehaviour
{
    public Picture minimap;
    public Rework border;

    personal float xOffset;
    personal float yOffset;

    // getting values from the participant van
    public CarController van;
    personal float yRotation;
    personal Vector3 eulerRotation;
    personal Quaternion rotation;
    personal float yMovement;
    personal float xMovement;
    public Vector3 Motion;

    void Begin()
    {
        // getting offset which modifications with display screen measurement
        xOffset = remodel.place.x;
        yOffset = remodel.place.y;
    }

    void Replace()
    {
        // Getting Y rotation of the van (course dealing with)
        yRotation = van.vanRotation.eulerAngles.y;
        // turning that right into a vector for rotation of airplane (in Z as rotation of map is on a unique airplane to van)
        eulerRotation = new Vector3(0, 0, yRotation);
        // changing euler angles into quaternion
        rotation.eulerAngles = eulerRotation;
        remodel.rotation = rotation ;

        // changing the place of the van on the actual map to motion of the picture, 0.247... is the dimensions of the picture, whereas x and
        // y offset account for screensize
        yMovement= (-van.remodel.place.x * (float)0.24721213) + (float) + yOffset;
        xMovement = (-van.remodel.place.z * (float)0.24721213) + (float) + xOffset;
        Motion = new Vector3(xMovement, yMovement, 0);
        remodel.place = Motion;
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments