Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Quaternion Rotations CanvasUI

Discussion in 'Scripting' started by mexicano, Mar 7, 2019.

  1. mexicano

    mexicano

    Joined:
    Nov 12, 2013
    Posts:
    23
    I am trying to do an accelerometer and I got all figured out but I can't rotate my marker on the rectTransform Z axis and maintain X=0 and Y=0

    the closest I could get was :
    AngletoRotate is a value between 0 - 230
    rectTransform.rotation = Quaternion.Euler(0, 0, AngletoRotate);
    this one works perfectly but when I move my camera it also moves the marker...

    I recorded a video of what I want and the problem I am having:
    At the beginning of the video, you will see it working properly but when I decide to rotate the camera it breaks.

    I don't know how to fix it ...Pls help =(
     
  2. zxc76_die

    zxc76_die

    Joined:
    Apr 10, 2018
    Posts:
    9
    AngletoRotate = 180 / 230 * speed;

    180 - how many degrees in the speedometer
    230 - max speed
     
  3. mexicano

    mexicano

    Joined:
    Nov 12, 2013
    Posts:
    23
    its 0 to 230 I have the math done already for getting the value. the problem is making unity do the rotation.
    I know the angle rotation in Z i want is
    float AngletoRotate = 230 - ((percentageMagnitude) * (MaxTreshhold - MinTreshHold) * -1);
    but caling is not the correct way to go .
    rectTransform.rotation = Quaternion.Euler(0, 0, AngletoRotate);

    I want to hard set the rotation to the values (0,0,AngletoRotate) but I don't know how to do this
     
  4. mexicano

    mexicano

    Joined:
    Nov 12, 2013
    Posts:
    23
    I think I found the solution. It was
    rectTransform.rotation = Quaternion.Euler(rectTransform.eulerAngles.x, rectTransform.eulerAngles.y, AngletoRotate);
    instead of :
    rectTransform.rotation = Quaternion.Euler(0, 0, AngletoRotate);
    wwhat a nightmare... well thansk anyway zxc76_die