U
U
Uncle Bogdan2021-05-06 16:10:34
Unity
Uncle Bogdan, 2021-05-06 16:10:34

How to add extra degrees to an object?

I'm doing something like assembling a PC. But there is a problem, if the object is not level, then the RAM does not rise evenly (you can see it on the video).
How to add degrees to stand up straight?

The code
using UnityEngine;

public class MotherBoardPlace : MonoBehaviour
{

    Collision collision;

    private void OnCollisionEnter(Collision collision)
    {
        this.collision = collision;
        switch(collision.collider.tag)
        {
            case "Processor":
                Place("ProcessorPlace", new Vector3(0, 0, 90));
                break;
            case "ram":
                Place("RamPlace", new Vector3(0, 90, 0));
                break;
            case "CpuFan":
                Place("CpuFanPlace", new Vector3(0, 0, 0));
                break;
        }
    }

    private void Place(string PlaceName, Vector3 Angle)
    {
        collision.rigidbody.isKinematic = true;
        collision.rigidbody.detectCollisions = false;
        collision.rigidbody.useGravity = false;
        collision.transform.eulerAngles = Angle;
        collision.transform.parent = transform.Find(PlaceName);
        collision.transform.localPosition = new Vector3(0, 0, 0);
        Grabbing.grab = false;
    }
}


Video

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prizm, 2021-05-08
@PrizmMARgh

When "docking" it is necessary to make the board a child object of the body, and then indicate to it the relative rotation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question